Skip to content

Commit

Permalink
Delete ARP entry before sending loopback data for STAUT randomized MAC
Browse files Browse the repository at this point in the history
  • Loading branch information
WFA-achuang committed Oct 12, 2021
1 parent 5424d9d commit 4fe8dc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions indigo_api_callback_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ static int send_loopback_data_handler(struct packet_wrapper *req, struct packet_
char dut_ip[64];
char dut_port[32];
char rate[16], pkt_count[16], pkt_size[16], recv_count[16], pkt_type[16];
char cmd[128];
int status = TLV_VALUE_STATUS_NOT_OK, recvd = 0;
char *message = TLV_VALUE_SEND_LOOPBACK_DATA_NOT_OK;

Expand Down Expand Up @@ -639,6 +640,9 @@ static int send_loopback_data_handler(struct packet_wrapper *req, struct packet_
snprintf(pkt_type, sizeof(pkt_type), "udp");
}

/* Detect and delete existing ARP entry for STAUT randomized MAC */
detect_del_arp_entry(dut_ip);

/* Start loopback */
snprintf(recv_count, sizeof(recv_count), "0");

Expand Down
25 changes: 25 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,31 @@ int reset_interface_ip(char *ifname) {
return system(cmd);
}

void detect_del_arp_entry(char *ip) {
char buffer[S_BUFFER_LEN];
char res_ip[32], res_dev[16], res_inf[16];
FILE *fp;

snprintf(buffer, sizeof(buffer), "ip neigh show %s", ip);
fp = popen(buffer, "r");
if (fp == NULL)
return;

if (NULL == fgets(buffer, sizeof(buffer), fp)) {
} else if (3 == sscanf(buffer, "%s %s %s", res_ip, res_dev, res_inf)) {
if (!strcmp(res_ip, ip) && !strcmp(res_dev, "dev")) {
indigo_logger(LOG_LEVEL_INFO, "Delete existing ARP entry: %s", ip);
snprintf(buffer, sizeof(buffer), "ip neigh del %s %s %s", res_ip, res_dev, res_inf);
system(buffer);
} else {
indigo_logger(LOG_LEVEL_INFO, "Format mismatch?: %s %s %s\n", res_ip, res_dev, res_inf);
}
}
pclose(fp);

return;
}

int add_all_wireless_interface_to_bridge(char *br) {
int i;

Expand Down
1 change: 1 addition & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ int reset_interface_ip(char *ifname);
int add_wireless_interface(char *ifname);
int delete_wireless_interface(char *ifname);
void bridge_init(char *br);
void detect_del_arp_entry(char *ip);

#define DEBUG_LEVEL_DISABLE 0
#define DEBUG_LEVEL_BASIC 1
Expand Down

0 comments on commit 4fe8dc7

Please sign in to comment.