@@ -25,30 +25,29 @@ static cmd_status_t icmp_send(
2525 struct gr_ip6_icmp_send_req * req ,
2626 uint16_t msdelay ,
2727 uint16_t count ,
28+ uint16_t ident ,
2829 bool mode_traceroute
2930) {
3031 struct gr_ip6_icmp_recv_resp * reply_resp ;
3132 struct gr_ip6_icmp_recv_req reply_req ;
3233 int i , timeout , ret , errors ;
3334 void * resp_ptr = NULL ;
34- uint16_t ping_id ;
3535 const char * errdesc ;
3636
3737 stop = false;
3838 errors = 0 ;
3939 errno = 0 ;
40- ping_id = random ();
4140
4241 for (i = !!mode_traceroute ; i < count && stop == false; i ++ ) {
43- req -> ident = ping_id ;
42+ req -> ident = ident ;
4443 req -> seq_num = i ;
4544 req -> ttl = mode_traceroute ? i : 64 ;
4645
4746 ret = gr_api_client_send_recv (c , GR_IP6_ICMP6_SEND , sizeof (* req ), req , NULL );
4847 if (ret < 0 )
4948 return CMD_ERROR ;
5049
51- reply_req .ident = ping_id ;
50+ reply_req .ident = ident ;
5251 reply_req .seq_num = i ;
5352 timeout = 50 ;
5453 do {
@@ -142,6 +141,7 @@ static cmd_status_t ping(struct gr_api_client *c, const struct ec_pnode *p) {
142141 struct gr_ip6_icmp_send_req req = {.iface = GR_IFACE_ID_UNDEF , .vrf = 0 };
143142 cmd_status_t ret = CMD_ERROR ;
144143 uint16_t count = UINT16_MAX ;
144+ uint16_t ident = random ();
145145 uint16_t msdelay = 1000 ;
146146 const char * str ;
147147
@@ -153,6 +153,8 @@ static cmd_status_t ping(struct gr_api_client *c, const struct ec_pnode *p) {
153153 return CMD_ERROR ;
154154 if ((ret = arg_u16 (p , "DELAY" , & msdelay )) < 0 && ret != ENOENT )
155155 return CMD_ERROR ;
156+ if ((ret = arg_u16 (p , "IDENT" , & ident )) < 0 && ret != ENOENT )
157+ return CMD_ERROR ;
156158 if ((str = arg_str (p , "IFACE" )) != NULL ) {
157159 struct gr_iface * iface = iface_from_name (c , str );
158160 if (iface == NULL )
@@ -165,7 +167,7 @@ static cmd_status_t ping(struct gr_api_client *c, const struct ec_pnode *p) {
165167 if (prev_handler == SIG_ERR )
166168 return CMD_ERROR ;
167169
168- ret = icmp_send (c , & req , msdelay , count , false);
170+ ret = icmp_send (c , & req , msdelay , count , ident , false);
169171
170172 signal (SIGINT , prev_handler );
171173
@@ -175,12 +177,15 @@ static cmd_status_t ping(struct gr_api_client *c, const struct ec_pnode *p) {
175177static cmd_status_t traceroute (struct gr_api_client * c , const struct ec_pnode * p ) {
176178 struct gr_ip6_icmp_send_req req = {.iface = GR_IFACE_ID_UNDEF , .vrf = 0 };
177179 cmd_status_t ret = CMD_SUCCESS ;
180+ uint16_t ident = random ();
178181 const char * str ;
179182
180183 if (arg_ip6 (p , "DEST" , & req .addr ) < 0 )
181184 return CMD_ERROR ;
182185 if ((ret = arg_u16 (p , "VRF" , & req .vrf )) < 0 && ret != ENOENT )
183186 return CMD_ERROR ;
187+ if ((ret = arg_u16 (p , "IDENT" , & ident )) < 0 && ret != ENOENT )
188+ return CMD_ERROR ;
184189 if ((str = arg_str (p , "IFACE" )) != NULL ) {
185190 struct gr_iface * iface = iface_from_name (c , str );
186191 if (iface == NULL )
@@ -193,7 +198,7 @@ static cmd_status_t traceroute(struct gr_api_client *c, const struct ec_pnode *p
193198 if (prev_handler == SIG_ERR )
194199 return CMD_ERROR ;
195200
196- ret = icmp_send (c , & req , 0 , 255 , true);
201+ ret = icmp_send (c , & req , 0 , 255 , ident , true);
197202
198203 signal (SIGINT , prev_handler );
199204
@@ -207,7 +212,7 @@ static int ctx_init(struct ec_node *root) {
207212 CLI_CONTEXT (
208213 root , CTX_ARG ("ping" , "Send ICMPv6 echo requests and wait for replies." )
209214 ),
210- "DEST [vrf VRF] [count COUNT] [delay DELAY] [iface IFACE]" ,
215+ "DEST [vrf VRF] [count COUNT] [delay DELAY] [iface IFACE] [ident IDENT] " ,
211216 ping ,
212217 "Send ICMPv6 echo requests and wait for replies." ,
213218 with_help ("IPv6 destination address." , ec_node_re ("DEST" , IPV6_RE )),
@@ -217,21 +222,29 @@ static int ctx_init(struct ec_node *root) {
217222 ),
218223 with_help ("L3 routing domain ID." , ec_node_uint ("VRF" , 0 , UINT16_MAX - 1 , 10 )),
219224 with_help ("Number of packets to send." , ec_node_uint ("COUNT" , 1 , UINT16_MAX , 10 )),
220- with_help ("Delay in ms between icmp6 echo." , ec_node_uint ("DELAY" , 0 , 10000 , 10 ))
225+ with_help ("Delay in ms between icmp6 echo." , ec_node_uint ("DELAY" , 0 , 10000 , 10 )),
226+ with_help (
227+ "Icmp ident field (default: random)." ,
228+ ec_node_uint ("IDENT" , 1 , UINT16_MAX , 10 )
229+ )
221230 );
222231 if (ret < 0 )
223232 return ret ;
224233
225234 ret = CLI_COMMAND (
226235 CLI_CONTEXT (root , CTX_ARG ("traceroute" , "Discover IPv6 intermediate gateways." )),
227- "DEST [vrf VRF] [iface IFACE]" ,
236+ "DEST [vrf VRF] [iface IFACE] [ident IDENT] " ,
228237 traceroute ,
229238 "Discover IPv6 intermediate gateways." ,
230239 with_help ("IPv6 destination address." , ec_node_re ("DEST" , IPV6_RE )),
231240 with_help ("L3 routing domain ID." , ec_node_uint ("VRF" , 0 , UINT16_MAX - 1 , 10 )),
232241 with_help (
233242 "Output interface name." ,
234243 ec_node_dyn ("IFACE" , complete_iface_names , INT2PTR (GR_IFACE_TYPE_UNDEF ))
244+ ),
245+ with_help (
246+ "Icmp ident field (default: random)." ,
247+ ec_node_uint ("IDENT" , 1 , UINT16_MAX , 10 )
235248 )
236249 );
237250
0 commit comments