41
41
#include <errno.h>
42
42
#include <getopt.h>
43
43
#include <assert.h>
44
+ #include <unistd.h>
45
+ #include <net/if.h>
46
+ #include <arpa/inet.h>
47
+ #include <spawn.h>
44
48
45
49
#include <netinet/in.h>
46
- #include <linux/if.h>
47
- #include <linux/if_tun.h>
48
50
#include <fcntl.h>
49
51
#include <sys/ioctl.h>
50
52
#include <unistd.h>
@@ -117,13 +119,16 @@ static int ans_kni_config_iface(uint8_t port_id, uint8_t if_up)
117
119
{
118
120
int ret = 0 ;
119
121
122
+ printf ("Don't allow to set port UP/DOWN. Always return successfully \n" );
123
+
124
+ /*
120
125
if (port_id >= rte_eth_dev_count())
121
126
return -EINVAL;
122
127
123
128
ret = (if_up) ?
124
129
rte_eth_dev_set_link_up(port_id) :
125
130
rte_eth_dev_set_link_down(port_id);
126
-
131
+ */
127
132
return ret ;
128
133
}
129
134
@@ -203,7 +208,7 @@ static int ans_kni_alloc(uint8_t port_id)
203
208
memset (& ops , 0 , sizeof (ops ));
204
209
ops .port_id = port_id ;
205
210
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 ;
207
212
208
213
kni = rte_kni_alloc (kni_mempool , & conf , & ops );
209
214
@@ -313,6 +318,38 @@ int ans_kni_config(struct ans_user_config * common_config, struct rte_mempool *
313
318
return 0 ;
314
319
}
315
320
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
+
316
353
/**********************************************************************
317
354
*@description:
318
355
*
@@ -399,36 +436,27 @@ static int ans_kni_free(uint8_t port_id)
399
436
*@return values:
400
437
*
401
438
**********************************************************************/
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 )
403
440
{
404
441
uint8_t i , port_id ;
405
442
unsigned nb_rx , num ;
406
443
struct rte_mbuf * pkts_burst [PKT_BURST_SZ ];
407
444
408
- if ( p == NULL )
409
- return ;
445
+ /* handle kin request event */
446
+ rte_kni_handle_request ( port_param -> kni ) ;
410
447
411
- port_id = p -> port_id ;
448
+ port_id = port_param -> port_id ;
412
449
413
450
/* 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 );
422
452
if (nb_rx == 0 )
423
453
{
424
454
return ;
425
455
}
426
456
427
457
/* 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 );
429
459
//kni_stats[port_id].rx_packets += num;
430
-
431
- rte_kni_handle_request (p -> kni );
432
460
if (unlikely (num < nb_rx ))
433
461
{
434
462
/* Free mbufs not tx to kni interface */
@@ -450,20 +478,17 @@ static inline void ans_kni_to_linux(struct kni_port_params *p)
450
478
*@return values:
451
479
*
452
480
**********************************************************************/
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 )
454
482
{
455
483
uint8_t i , port_id ;
456
484
unsigned nb_tx , num ;
457
485
uint32_t nb_kni ;
458
486
struct rte_mbuf * pkts_burst [PKT_BURST_SZ ];
459
487
460
- if (p == NULL )
461
- return ;
462
-
463
- port_id = p -> port_id ;
488
+ port_id = port_param -> port_id ;
464
489
465
490
/* 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 );
467
492
if (unlikely (num > PKT_BURST_SZ ))
468
493
{
469
494
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)
502
527
**********************************************************************/
503
528
void ans_kni_main ()
504
529
{
530
+ int i ;
505
531
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 ];
507
534
508
- if (unlikely (lcore == NULL ))
535
+ if (unlikely (! lcore_param ))
509
536
return ;
510
537
511
- for (int i = 0 ; i < lcore -> nb_ports ; i ++ )
538
+ for (i = 0 ; i < lcore_param -> nb_ports ; i ++ )
512
539
{
513
- struct kni_port_params * port = lcore -> port [i ];
540
+ port_param = lcore_param -> port [i ];
514
541
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 );
517
544
}
518
545
519
546
return ;
0 commit comments