net: VLAN cleanup
PATCH 1/1 net: VLAN cleanup
- strip priority bits in received packets. We do not control them and need to compare VLAN number only, which takes just 12 bits.
- store VLAN number and priority bits separately in interface structure.
- fix VLAN comparison when searching for matching interface. We need to continiue, not break out of loop, if VLAN number does not match.
- add missing VLAN check in BOOTP/DHCP processing.
- introduce 802.1Q header structure to avoid shuffling parts of packet around. This streamlines code and makes it more clear.
- remove misleading dprintf - non-matching VLAN is not really an error. It is quite possible to have multiple interfaces on the same physical card with different VLAN numbers.
- pass VLAN number by value, there is no need to use reference.
- print VLAN ID in net_ls_addr
--- grub-core/net/arp.c | 10 ++--- grub-core/net/drivers/ieee1275/ofnet.c | 4 +- grub-core/net/ethernet.c | 79 +++++++++++++++++----------------- grub-core/net/ip.c | 21 ++++----- grub-core/net/net.c | 5 ++- include/grub/net.h | 3 +- include/grub/net/arp.h | 2 +- include/grub/net/ethernet.h | 1 + include/grub/net/ip.h | 2 +- 9 files changed, 62 insertions(+), 65 deletions(-)
grub-core/net/arp.c +3 -7
@@ -112,7 +112,7 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf,grub_err_t grub_net_arp_receive (struct grub_net_buff *nb,struct grub_net_card *card, -grub_uint16_t *vlantag) +grub_uint16_t vlantag) {struct arppkt *arp_packet = (struct arppkt *) nb->data;grub_net_network_level_address_t sender_addr, target_addr;
@@ -139,12 +139,8 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,FOR_NET_NETWORK_LEVEL_INTERFACES (inf) {/* Verify vlantag id */ -if (inf->card == card && inf->vlantag != *vlantag) - { -grub_dprintf ("net" ,"invalid vlantag! %x != %x\n" , - inf->vlantag, *vlantag); -break ; - } +if (inf->vlantag != vlantag) +continue ;/* Am I the protocol address target? */ if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
grub-core/net/drivers/ieee1275/ofnet.c +2 -2
@@ -212,10 +212,10 @@ grub_ieee1275_parse_bootargs (const char *devpath, char *bootpath, hw_addr.mac, sizeof(hw_addr.mac), 0); inter =grub_net_add_addr ((*card)->name, *card, &client_addr, &hw_addr, flags); - inter->vlantag = vlantag; + inter->vlantag = vlantag &0xfff ; + inter->prio = vlantag &0xf000 ;grub_net_add_ipv4_local (inter,__builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4))); - }if (gateway_addr.ipv4 !=0 )
grub-core/net/ethernet.c +40 -39
130 lines not on this page · raw message
grub-core/net/ip.c +9 -12
@@ -228,7 +228,7 @@ handle_dgram (struct grub_net_buff *nb,grub_net_ip_protocol_t proto, const grub_net_network_level_address_t *source, const grub_net_network_level_address_t *dest, - grub_uint16_t *vlantag, + grub_uint16_t vlantag, grub_uint8_t ttl) { struct grub_net_network_level_interface *inf = NULL;
@@ -274,6 +274,7 @@ handle_dgram (struct grub_net_buff *nb, FOR_NET_NETWORK_LEVEL_INTERFACES (inf) if (inf->card == card + && inf->vlantag == vlantag && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr,
@@ -290,19 +291,15 @@ handle_dgram (struct grub_net_buff *nb,FOR_NET_NETWORK_LEVEL_INTERFACES (inf) { +/* Verify vlantag id */ +if (inf->vlantag != vlantag) +continue ; +if (inf->card == card &&grub_net_addr_cmp (&inf->address, dest) ==0 &&grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) ==0 )break ; -/* Verify vlantag id */ -if (inf->card == card && inf->vlantag != *vlantag) - { -grub_dprintf ("net" ,"invalid vlantag! %x != %x\n" , - inf->vlantag, *vlantag); -break ; - } -/* Solicited node multicast. */ if (inf->card == card && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6
@@ -392,7 +389,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb,struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag) { struct iphdr *iph = (struct iphdr *) nb->data;grub_err_t err;
@@ -662,7 +659,7 @@ grub_net_recv_ip6_packets (struct grub_net_buff *nb,struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag) { struct ip6hdr *iph = (struct ip6hdr *) nb->data;grub_err_t err;
@@ -721,7 +718,7 @@ grub_net_recv_ip_packets (struct grub_net_buff *nb,struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag) { struct iphdr *iph = (struct iphdr *) nb->data;
grub-core/net/net.c +4 -1
@@ -1247,7 +1247,10 @@ grub_cmd_listaddrs (struct grub_command *cmd __attribute__ ((unused)),char bufn[GRUB_NET_MAX_STR_ADDR_LEN ];grub_net_hwaddr_to_str (&inf->hwaddress, bufh);grub_net_addr_to_str (&inf->address, bufn); -grub_printf ("%s %s %s\n" , inf->name, bufh, bufn); +grub_printf ("%s %s %s" , inf->name, bufh, bufn); +if (inf->vlantag) +grub_printf (" VID=%u" , inf->vlantag); +grub_printf ("\n" ); }return GRUB_ERR_NONE ; }
include/grub/net.h +1 -2
@@ -292,6 +292,7 @@ struct grub_net_network_level_interfacestruct grub_net_bootp_packet *dhcp_ack;grub_size_t dhcp_acklen;grub_uint16_t vlantag; +grub_uint16_t prio;void *data; };
@@ -562,6 +563,4 @@ extern char *grub_net_default_server;#define GRUB_NET_INTERVAL 400#define GRUB_NET_INTERVAL_ADDITION 20 -#define VLANTAG_IDENTIFIER 0x8100 -#endif /* ! GRUB_NET_HEADER */
include/grub/net/arp.h +1 -1
@@ -23,7 +23,7 @@extern grub_err_t grub_net_arp_receive (struct grub_net_buff *nb,struct grub_net_card *card, -grub_uint16_t *vlantag); +grub_uint16_t vlantag); grub_err_t grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
include/grub/net/ethernet.h +1 -0
@@ -27,6 +27,7 @@ typedef enumGRUB_NET_ETHERTYPE_IP =0x0800 ,GRUB_NET_ETHERTYPE_ARP =0x0806 ,GRUB_NET_ETHERTYPE_IP6 =0x86DD , +GRUB_NET_ETHERTYPE_802_1Q =0x8100 , } grub_net_ethertype_t; grub_err_t
include/grub/net/ip.h +1 -1
@@ -49,7 +49,7 @@ grub_net_recv_ip_packets (struct grub_net_buff *nb,struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag); + grub_uint16_t vlantag); grub_err_t grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
Signature · 1 line
tg: (b4fc7bc..) n/vlan-cleanup (depends on: next)