Skip to content

Commit b0b13c2

Browse files
committed
support diffrent GW MAC for IPv4/v6 on netif
1 parent cbe3429 commit b0b13c2

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

code/bngblaster/src/bbl_network.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ bbl_network_interfaces_add()
102102

103103
/* Copy gateway MAC from config (default 00:00:00:00:00:00) */
104104
memcpy(network_interface->gateway_mac, network_config->gateway_mac, ETH_ADDR_LEN);
105+
memcpy(network_interface->gateway6_mac, network_config->gateway_mac, ETH_ADDR_LEN);
105106

106107
/* Init IPv4 */
107108
if(network_config->ip.address && network_config->gateway) {
@@ -350,7 +351,7 @@ bbl_network_rx_arp(bbl_network_interface_s *interface, bbl_ethernet_header_s *et
350351
bbl_arp_s *arp = (bbl_arp_s*)eth->next;
351352
if(arp->sender_ip == interface->gateway) {
352353
interface->arp_resolved = true;
353-
if(*(uint32_t*)interface->gateway_mac == 0) {
354+
if(memcmp(interface->gateway_mac, "\x00\x00\x00\x00\x00\x00", ETH_ADDR_LEN) == 0) {
354355
memcpy(interface->gateway_mac, arp->sender, ETH_ADDR_LEN);
355356
}
356357
}
@@ -385,13 +386,13 @@ bbl_network_rx_icmpv6(bbl_network_interface_s *interface,
385386
if(icmpv6->type == IPV6_ICMPV6_NEIGHBOR_ADVERTISEMENT) {
386387
if(memcmp(icmpv6->prefix.address, interface->gateway6, IPV6_ADDR_LEN) == 0) {
387388
interface->icmpv6_nd_resolved = true;
388-
if(*(uint32_t*)interface->gateway_mac == 0) {
389+
if(memcmp(interface->gateway6_mac, "\x00\x00\x00\x00\x00\x00", ETH_ADDR_LEN) == 0) {
389390
if(icmpv6->dst_mac == NULL) {
390391
gw_mac = eth->src;
391392
} else {
392393
gw_mac = icmpv6->dst_mac;
393394
}
394-
memcpy(interface->gateway_mac, gw_mac, ETH_ADDR_LEN);
395+
memcpy(interface->gateway6_mac, gw_mac, ETH_ADDR_LEN);
395396
}
396397
}
397398
} else if(icmpv6->type == IPV6_ICMPV6_NEIGHBOR_SOLICITATION) {

code/bngblaster/src/bbl_network.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct bbl_network_interface_
3030

3131
uint8_t mac[ETH_ADDR_LEN];
3232
uint8_t gateway_mac[ETH_ADDR_LEN];
33+
uint8_t gateway6_mac[ETH_ADDR_LEN];
3334

3435
uint32_t send_requests;
3536

code/bngblaster/src/bbl_stream.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ bbl_stream_build_network_packet(bbl_stream_s *stream)
676676
return false;
677677
}
678678

679-
eth.dst = network_interface->gateway_mac;
680679
eth.src = network_interface->mac;
681680
eth.vlan_outer = network_interface->vlan;
682681
eth.vlan_outer_priority = config->vlan_priority;
@@ -723,6 +722,7 @@ bbl_stream_build_network_packet(bbl_stream_s *stream)
723722
bbl.direction = BBL_DIRECTION_DOWN;
724723
switch(stream->sub_type) {
725724
case BBL_SUB_TYPE_IPV4:
725+
eth.dst = network_interface->gateway_mac;
726726
eth.type = ETH_TYPE_IPV4;
727727
eth.next = &ipv4;
728728

@@ -773,6 +773,7 @@ bbl_stream_build_network_packet(bbl_stream_s *stream)
773773
break;
774774
case BBL_SUB_TYPE_IPV6:
775775
case BBL_SUB_TYPE_IPV6PD:
776+
eth.dst = network_interface->gateway6_mac;
776777
eth.type = ETH_TYPE_IPV6;
777778
eth.next = &ipv6;
778779
/* Source address */

code/bngblaster/src/bbl_tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ bbl_tcp_netif_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t
10701070
bbl_ethernet_header_s eth = {0};
10711071
UNUSED(ipaddr);
10721072

1073-
eth.dst = interface->gateway_mac;
1073+
eth.dst = interface->gateway6_mac;
10741074
eth.src = interface->mac;
10751075
eth.vlan_outer = interface->vlan;
10761076
eth.type = ETH_TYPE_IPV6;

0 commit comments

Comments
 (0)