tests: Allow TX/RX data test to use different frame length

This is needed for MACsec test cases with a bit shorter MTU.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2018-12-24 23:56:25 +02:00
parent 7c6acc757b
commit 93701b4afe
2 changed files with 73 additions and 18 deletions

View file

@ -13,7 +13,8 @@ from wpasupplicant import WpaSupplicant
def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
ifname1=None, ifname2=None, config=True, timeout=5, ifname1=None, ifname2=None, config=True, timeout=5,
multicast_to_unicast=False, broadcast=True): multicast_to_unicast=False, broadcast=True,
send_len=None):
addr1 = dev1.own_addr() addr1 = dev1.own_addr()
if not dev1group and isinstance(dev1, WpaSupplicant): if not dev1group and isinstance(dev1, WpaSupplicant):
addr = dev1.get_driver_status_field('addr') addr = dev1.get_driver_status_field('addr')
@ -57,6 +58,8 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
raise Exception("Failed to enable data test functionality") raise Exception("Failed to enable data test functionality")
cmd = "DATA_TEST_TX {} {} {}".format(addr2, addr1, tos) cmd = "DATA_TEST_TX {} {} {}".format(addr2, addr1, tos)
if send_len is not None:
cmd += " len=" + str(send_len)
if dev1group: if dev1group:
dev1.group_request(cmd) dev1.group_request(cmd)
else: else:
@ -69,9 +72,17 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
raise Exception("dev1->dev2 unicast data delivery failed") raise Exception("dev1->dev2 unicast data delivery failed")
if "DATA-TEST-RX {} {}".format(addr2, addr1) not in ev: if "DATA-TEST-RX {} {}".format(addr2, addr1) not in ev:
raise Exception("Unexpected dev1->dev2 unicast data result") raise Exception("Unexpected dev1->dev2 unicast data result")
if send_len is not None:
if " len=" + str(send_len) not in ev:
raise Exception("Unexpected dev1->dev2 unicast data length")
else:
if " len=" in ev:
raise Exception("Unexpected dev1->dev2 unicast data length")
if broadcast: if broadcast:
cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr1, tos) cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr1, tos)
if send_len is not None:
cmd += " len=" + str(send_len)
for i in xrange(broadcast_retry_c): for i in xrange(broadcast_retry_c):
try: try:
if dev1group: if dev1group:
@ -87,12 +98,20 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
raise Exception("dev1->dev2 broadcast data delivery failed") raise Exception("dev1->dev2 broadcast data delivery failed")
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr1) not in ev: if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr1) not in ev:
raise Exception("Unexpected dev1->dev2 broadcast data result") raise Exception("Unexpected dev1->dev2 broadcast data result")
if send_len is not None:
if " len=" + str(send_len) not in ev:
raise Exception("Unexpected dev1->dev2 broadcast data length")
else:
if " len=" in ev:
raise Exception("Unexpected dev1->dev2 broadcast data length")
break break
except Exception as e: except Exception as e:
if i == broadcast_retry_c - 1: if i == broadcast_retry_c - 1:
raise raise
cmd = "DATA_TEST_TX {} {} {}".format(addr1, addr2, tos) cmd = "DATA_TEST_TX {} {} {}".format(addr1, addr2, tos)
if send_len is not None:
cmd += " len=" + str(send_len)
if dev2group: if dev2group:
dev2.group_request(cmd) dev2.group_request(cmd)
else: else:
@ -105,9 +124,17 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
raise Exception("dev2->dev1 unicast data delivery failed") raise Exception("dev2->dev1 unicast data delivery failed")
if "DATA-TEST-RX {} {}".format(addr1, addr2) not in ev: if "DATA-TEST-RX {} {}".format(addr1, addr2) not in ev:
raise Exception("Unexpected dev2->dev1 unicast data result") raise Exception("Unexpected dev2->dev1 unicast data result")
if send_len is not None:
if " len=" + str(send_len) not in ev:
raise Exception("Unexpected dev2->dev1 unicast data length")
else:
if " len=" in ev:
raise Exception("Unexpected dev2->dev1 unicast data length")
if broadcast: if broadcast:
cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr2, tos) cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr2, tos)
if send_len is not None:
cmd += " len=" + str(send_len)
for i in xrange(broadcast_retry_c): for i in xrange(broadcast_retry_c):
try: try:
if dev2group: if dev2group:
@ -129,6 +156,12 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
else: else:
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr2) not in ev: if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr2) not in ev:
raise Exception("Unexpected dev2->dev1 broadcast data result") raise Exception("Unexpected dev2->dev1 broadcast data result")
if send_len is not None:
if " len=" + str(send_len) not in ev:
raise Exception("Unexpected dev2->dev1 broadcast data length")
else:
if " len=" in ev:
raise Exception("Unexpected dev2->dev1 broadcast data length")
break break
except Exception as e: except Exception as e:
if i == broadcast_retry_c - 1: if i == broadcast_retry_c - 1:
@ -148,7 +181,7 @@ def test_connectivity(dev1, dev2, dscp=None, tos=None, max_tries=1,
dev1group=False, dev2group=False, dev1group=False, dev2group=False,
ifname1=None, ifname2=None, config=True, timeout=5, ifname1=None, ifname2=None, config=True, timeout=5,
multicast_to_unicast=False, success_expected=True, multicast_to_unicast=False, success_expected=True,
broadcast=True): broadcast=True, send_len=None):
if dscp: if dscp:
tos = dscp << 2 tos = dscp << 2
if not tos: if not tos:
@ -162,7 +195,7 @@ def test_connectivity(dev1, dev2, dscp=None, tos=None, max_tries=1,
ifname1, ifname2, config=config, ifname1, ifname2, config=config,
timeout=timeout, timeout=timeout,
multicast_to_unicast=multicast_to_unicast, multicast_to_unicast=multicast_to_unicast,
broadcast=broadcast) broadcast=broadcast, send_len=send_len)
success = True success = True
break break
except Exception, e: except Exception, e:

View file

@ -8779,26 +8779,39 @@ static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
struct iphdr ip; struct iphdr ip;
const u8 *pos; const u8 *pos;
unsigned int i; unsigned int i;
char extra[30];
if (len != HWSIM_PACKETLEN) if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
wpa_printf(MSG_DEBUG,
"test data: RX - ignore unexpected length %d",
(int) len);
return; return;
}
eth = (const struct ether_header *) buf; eth = (const struct ether_header *) buf;
os_memcpy(&ip, eth + 1, sizeof(ip)); os_memcpy(&ip, eth + 1, sizeof(ip));
pos = &buf[sizeof(*eth) + sizeof(ip)]; pos = &buf[sizeof(*eth) + sizeof(ip)];
if (ip.ihl != 5 || ip.version != 4 || if (ip.ihl != 5 || ip.version != 4 ||
ntohs(ip.tot_len) != HWSIM_IP_LEN) ntohs(ip.tot_len) > HWSIM_IP_LEN) {
wpa_printf(MSG_DEBUG,
"test data: RX - ignore unexpect IP header");
return; return;
for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
if (*pos != (u8) i)
return;
pos++;
} }
wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR, for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) {
MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost)); if (*pos != (u8) i) {
wpa_printf(MSG_DEBUG,
"test data: RX - ignore mismatching payload");
return;
}
pos++;
}
extra[0] = '\0';
if (ntohs(ip.tot_len) != HWSIM_IP_LEN)
os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len));
wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
} }
@ -8842,7 +8855,7 @@ static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
{ {
u8 dst[ETH_ALEN], src[ETH_ALEN]; u8 dst[ETH_ALEN], src[ETH_ALEN];
char *pos; char *pos, *pos2;
int used; int used;
long int val; long int val;
u8 tos; u8 tos;
@ -8851,11 +8864,12 @@ static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
struct iphdr *ip; struct iphdr *ip;
u8 *dpos; u8 *dpos;
unsigned int i; unsigned int i;
size_t send_len = HWSIM_IP_LEN;
if (wpa_s->l2_test == NULL) if (wpa_s->l2_test == NULL)
return -1; return -1;
/* format: <dst> <src> <tos> */ /* format: <dst> <src> <tos> [len=<length>] */
pos = cmd; pos = cmd;
used = hwaddr_aton2(pos, dst); used = hwaddr_aton2(pos, dst);
@ -8869,11 +8883,19 @@ static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
return -1; return -1;
pos += used; pos += used;
val = strtol(pos, NULL, 0); val = strtol(pos, &pos2, 0);
if (val < 0 || val > 0xff) if (val < 0 || val > 0xff)
return -1; return -1;
tos = val; tos = val;
pos = os_strstr(pos2, " len=");
if (pos) {
i = atoi(pos + 5);
if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
return -1;
send_len = i;
}
eth = (struct ether_header *) &buf[2]; eth = (struct ether_header *) &buf[2];
os_memcpy(eth->ether_dhost, dst, ETH_ALEN); os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
os_memcpy(eth->ether_shost, src, ETH_ALEN); os_memcpy(eth->ether_shost, src, ETH_ALEN);
@ -8884,17 +8906,17 @@ static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
ip->version = 4; ip->version = 4;
ip->ttl = 64; ip->ttl = 64;
ip->tos = tos; ip->tos = tos;
ip->tot_len = htons(HWSIM_IP_LEN); ip->tot_len = htons(send_len);
ip->protocol = 1; ip->protocol = 1;
ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
dpos = (u8 *) (ip + 1); dpos = (u8 *) (ip + 1);
for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) for (i = 0; i < send_len - sizeof(*ip); i++)
*dpos++ = i; *dpos++ = i;
if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
HWSIM_PACKETLEN) < 0) sizeof(struct ether_header) + send_len) < 0)
return -1; return -1;
wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR