4141#include <errno.h>
4242#include <getopt.h>
4343#include <assert.h>
44+ #include <unistd.h>
45+ #include <net/if.h>
46+ #include <arpa/inet.h>
47+ #include <spawn.h>
4448
4549#include <netinet/in.h>
46- #include <linux/if.h>
47- #include <linux/if_tun.h>
4850#include <fcntl.h>
4951#include <sys/ioctl.h>
5052#include <unistd.h>
@@ -117,13 +119,16 @@ static int ans_kni_config_iface(uint8_t port_id, uint8_t if_up)
117119{
118120 int ret = 0 ;
119121
122+ printf ("Don't allow to set port UP/DOWN. Always return successfully \n" );
123+
124+ /*
120125 if (port_id >= rte_eth_dev_count())
121126 return -EINVAL;
122127
123128 ret = (if_up) ?
124129 rte_eth_dev_set_link_up(port_id) :
125130 rte_eth_dev_set_link_down(port_id);
126-
131+ */
127132 return ret ;
128133}
129134
@@ -203,7 +208,7 @@ static int ans_kni_alloc(uint8_t port_id)
203208 memset (& ops , 0 , sizeof (ops ));
204209 ops .port_id = port_id ;
205210 ops .change_mtu = ans_kni_change_mtu ;
206- ops .config_network_if = ans_kni_config_iface ;
211+ ops .config_network_if = ans_kni_config_iface ;
207212
208213 kni = rte_kni_alloc (kni_mempool , & conf , & ops );
209214
@@ -313,6 +318,38 @@ int ans_kni_config(struct ans_user_config * common_config, struct rte_mempool *
313318 return 0 ;
314319}
315320
321+ /**********************************************************************
322+ *@description:
323+ *
324+ *
325+ *@parameters:
326+ * [in]:
327+ * [in]:
328+ *
329+ *@return values:
330+ *
331+ **********************************************************************/
332+ uint16_t ans_kni_id_get (uint8_t port )
333+ {
334+ uint32_t kni_id ;
335+ const char * kni_name ;
336+ struct kni_port_params * kni_port = kni_port_params_array [port ];
337+
338+ if (kni_port == NULL )
339+ {
340+ return 0 ;
341+ }
342+ else
343+ {
344+ kni_name = rte_kni_get_name (kni_port -> kni );
345+ kni_id = if_nametoindex (kni_name );
346+
347+ return kni_id ;
348+ }
349+
350+ return 0 ;
351+ }
352+
316353/**********************************************************************
317354*@description:
318355*
@@ -399,36 +436,27 @@ static int ans_kni_free(uint8_t port_id)
399436*@return values:
400437*
401438**********************************************************************/
402- static inline void ans_kni_to_linux (struct kni_port_params * p )
439+ static inline void ans_kni_to_linux (struct kni_port_params * port_param )
403440{
404441 uint8_t i , port_id ;
405442 unsigned nb_rx , num ;
406443 struct rte_mbuf * pkts_burst [PKT_BURST_SZ ];
407444
408- if ( p == NULL )
409- return ;
445+ /* handle kin request event */
446+ rte_kni_handle_request ( port_param -> kni ) ;
410447
411- port_id = p -> port_id ;
448+ port_id = port_param -> port_id ;
412449
413450 /* Burst rx from ring */
414- nb_rx = rte_ring_dequeue_burst (p -> ring ,(void * * )& pkts_burst , PKT_BURST_SZ , NULL );
415-
416- if (unlikely (nb_rx > PKT_BURST_SZ ))
417- {
418- RTE_LOG (ERR , USER8 , "Error receiving from eth\n" );
419- return ;
420- }
421-
451+ nb_rx = rte_ring_dequeue_burst (port_param -> ring ,(void * * )& pkts_burst , PKT_BURST_SZ , NULL );
422452 if (nb_rx == 0 )
423453 {
424454 return ;
425455 }
426456
427457 /* Burst tx to kni */
428- num = rte_kni_tx_burst (p -> kni , pkts_burst , nb_rx );
458+ num = rte_kni_tx_burst (port_param -> kni , pkts_burst , nb_rx );
429459 //kni_stats[port_id].rx_packets += num;
430-
431- rte_kni_handle_request (p -> kni );
432460 if (unlikely (num < nb_rx ))
433461 {
434462 /* Free mbufs not tx to kni interface */
@@ -450,20 +478,17 @@ static inline void ans_kni_to_linux(struct kni_port_params *p)
450478*@return values:
451479*
452480**********************************************************************/
453- static inline void ans_kni_to_eth (struct kni_port_params * p )
481+ static inline void ans_kni_to_eth (struct kni_port_params * port_param )
454482{
455483 uint8_t i , port_id ;
456484 unsigned nb_tx , num ;
457485 uint32_t nb_kni ;
458486 struct rte_mbuf * pkts_burst [PKT_BURST_SZ ];
459487
460- if (p == NULL )
461- return ;
462-
463- port_id = p -> port_id ;
488+ port_id = port_param -> port_id ;
464489
465490 /* Burst rx from kni */
466- num = rte_kni_rx_burst (p -> kni , pkts_burst , PKT_BURST_SZ );
491+ num = rte_kni_rx_burst (port_param -> kni , pkts_burst , PKT_BURST_SZ );
467492 if (unlikely (num > PKT_BURST_SZ ))
468493 {
469494 RTE_LOG (ERR , USER8 , "Error receiving from KNI\n" );
@@ -502,18 +527,20 @@ static inline void ans_kni_to_eth(struct kni_port_params *p)
502527**********************************************************************/
503528void ans_kni_main ()
504529{
530+ int i ;
505531 uint8_t lcore_id = rte_lcore_id ();
506- struct kni_lcore_params * lcore = kni_lcore_params_array [lcore_id ];
532+ struct kni_port_params * port_param ;
533+ struct kni_lcore_params * lcore_param = kni_lcore_params_array [lcore_id ];
507534
508- if (unlikely (lcore == NULL ))
535+ if (unlikely (! lcore_param ))
509536 return ;
510537
511- for (int i = 0 ; i < lcore -> nb_ports ; i ++ )
538+ for (i = 0 ; i < lcore_param -> nb_ports ; i ++ )
512539 {
513- struct kni_port_params * port = lcore -> port [i ];
540+ port_param = lcore_param -> port [i ];
514541
515- ans_kni_to_linux (port );
516- ans_kni_to_eth (port );
542+ ans_kni_to_linux (port_param );
543+ ans_kni_to_eth (port_param );
517544 }
518545
519546 return ;
0 commit comments