11
11
#include <gr_module.h>
12
12
#include <gr_queue.h>
13
13
14
- #include <rte_atomic.h>
15
14
#include <rte_icmp.h>
16
15
#include <rte_ip.h>
17
16
#include <rte_ring.h>
@@ -49,7 +48,7 @@ static void icmp_input_cb(struct rte_mbuf *m) {
49
48
50
49
// Search for the oldest ICMP response matching the given identifier.
51
50
// If found, the packet is removed from the queue.
52
- static struct rte_mbuf * get_icmp_response (uint16_t ident ) {
51
+ static struct rte_mbuf * get_icmp_response (uint16_t ident , uint16_t seq_num ) {
53
52
struct icmp_queue_item * i , * tmp ;
54
53
struct rte_mbuf * mbuf = NULL ;
55
54
@@ -78,7 +77,8 @@ static struct rte_mbuf *get_icmp_response(uint16_t ident) {
78
77
}
79
78
}
80
79
81
- if (rte_be_to_cpu_16 (icmp -> icmp_ident ) == ident ) {
80
+ if (rte_be_to_cpu_16 (icmp -> icmp_ident ) == ident
81
+ && rte_be_to_cpu_16 (icmp -> icmp_seq_nb ) == seq_num ) {
82
82
mbuf = i -> mbuf ;
83
83
icmp_queue_pop (i , false);
84
84
break ;
@@ -88,33 +88,18 @@ static struct rte_mbuf *get_icmp_response(uint16_t ident) {
88
88
return mbuf ;
89
89
}
90
90
91
- // Global id which is used to differentiate between api clients
92
- static rte_atomic16_t icmp_ident = RTE_ATOMIC16_INIT (0 );
93
-
94
- static struct api_out icmp_send (const void * request , void * * response ) {
91
+ static struct api_out icmp_send (const void * request , void * * /*response*/ ) {
95
92
const struct gr_ip4_icmp_send_req * req = request ;
96
- struct gr_ip4_icmp_send_resp * resp = NULL ;
97
93
const struct nexthop * nh ;
98
- int ret ;
99
-
100
- if ((resp = calloc (1 , sizeof (* resp ))) == NULL )
101
- return api_out (ENOMEM , 0 );
94
+ int ret = 0 ;
102
95
103
96
if ((nh = rib4_lookup (req -> vrf , req -> addr )) == NULL ) {
104
97
ret = - errno ;
105
- goto fail ;
98
+ goto out ;
106
99
}
107
100
108
- resp -> ident = rte_atomic16_add_return (& icmp_ident , 1 );
109
- ret = icmp_local_send (req -> vrf , req -> addr , nh , resp -> ident , req -> seq_num , req -> ttl );
110
- if (ret < 0 )
111
- goto fail ;
112
-
113
- * response = resp ;
114
-
115
- return api_out (0 , sizeof (* resp ));
116
- fail :
117
- free (resp );
101
+ ret = icmp_local_send (req -> vrf , req -> addr , nh , req -> ident , req -> seq_num , req -> ttl );
102
+ out :
118
103
return api_out (- ret , 0 );
119
104
}
120
105
@@ -128,7 +113,7 @@ static struct api_out icmp_recv(const void *request, void **response) {
128
113
size_t len = 0 ;
129
114
int ret = 0 ;
130
115
131
- m = get_icmp_response (icmp_req -> ident );
116
+ m = get_icmp_response (icmp_req -> ident , icmp_req -> seq_num );
132
117
if (m == NULL )
133
118
return api_out (0 , 0 );
134
119
0 commit comments