Commit cbfc16de30d4c3a7bb6050d0c88fb6cb35f47d04

Authored by Linus Lüssing
Committed by Simon Wunderlich
1 parent 75721643d5

batman-adv: Add wrapper for ARP reply creation

Removing duplicate code.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>

Showing 1 changed file with 40 additions and 27 deletions Side-by-side Diff

net/batman-adv/distributed-arp-table.c
... ... @@ -949,6 +949,41 @@
949 949 }
950 950  
951 951 /**
  952 + * batadv_dat_arp_create_reply - create an ARP Reply
  953 + * @bat_priv: the bat priv with all the soft interface information
  954 + * @ip_src: ARP sender IP
  955 + * @ip_dst: ARP target IP
  956 + * @hw_src: Ethernet source and ARP sender MAC
  957 + * @hw_dst: Ethernet destination and ARP target MAC
  958 + * @vid: VLAN identifier (optional, set to zero otherwise)
  959 + *
  960 + * Creates an ARP Reply from the given values, optionally encapsulated in a
  961 + * VLAN header.
  962 + *
  963 + * Return: An skb containing an ARP Reply.
  964 + */
  965 +static struct sk_buff *
  966 +batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
  967 + __be32 ip_dst, u8 *hw_src, u8 *hw_dst,
  968 + unsigned short vid)
  969 +{
  970 + struct sk_buff *skb;
  971 +
  972 + skb = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_dst, bat_priv->soft_iface,
  973 + ip_src, hw_dst, hw_src, hw_dst);
  974 + if (!skb)
  975 + return NULL;
  976 +
  977 + skb_reset_mac_header(skb);
  978 +
  979 + if (vid & BATADV_VLAN_HAS_TAG)
  980 + skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
  981 + vid & VLAN_VID_MASK);
  982 +
  983 + return skb;
  984 +}
  985 +
  986 +/**
952 987 * batadv_dat_snoop_outgoing_arp_request - snoop the ARP request and try to
953 988 * answer using DAT
954 989 * @bat_priv: the bat priv with all the soft interface information
955 990  
... ... @@ -1005,20 +1040,12 @@
1005 1040 goto out;
1006 1041 }
1007 1042  
1008   - skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src,
1009   - bat_priv->soft_iface, ip_dst, hw_src,
1010   - dat_entry->mac_addr, hw_src);
  1043 + skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
  1044 + dat_entry->mac_addr,
  1045 + hw_src, vid);
1011 1046 if (!skb_new)
1012 1047 goto out;
1013 1048  
1014   - if (vid & BATADV_VLAN_HAS_TAG) {
1015   - skb_new = vlan_insert_tag(skb_new, htons(ETH_P_8021Q),
1016   - vid & VLAN_VID_MASK);
1017   - if (!skb_new)
1018   - goto out;
1019   - }
1020   -
1021   - skb_reset_mac_header(skb_new);
1022 1049 skb_new->protocol = eth_type_trans(skb_new,
1023 1050 bat_priv->soft_iface);
1024 1051 bat_priv->stats.rx_packets++;
1025 1052  
... ... @@ -1081,24 +1108,10 @@
1081 1108 if (!dat_entry)
1082 1109 goto out;
1083 1110  
1084   - skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src,
1085   - bat_priv->soft_iface, ip_dst, hw_src,
1086   - dat_entry->mac_addr, hw_src);
1087   -
  1111 + skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
  1112 + dat_entry->mac_addr, hw_src, vid);
1088 1113 if (!skb_new)
1089 1114 goto out;
1090   -
1091   - /* the rest of the TX path assumes that the mac_header offset pointing
1092   - * to the inner Ethernet header has been set, therefore reset it now.
1093   - */
1094   - skb_reset_mac_header(skb_new);
1095   -
1096   - if (vid & BATADV_VLAN_HAS_TAG) {
1097   - skb_new = vlan_insert_tag(skb_new, htons(ETH_P_8021Q),
1098   - vid & VLAN_VID_MASK);
1099   - if (!skb_new)
1100   - goto out;
1101   - }
1102 1115  
1103 1116 /* To preserve backwards compatibility, the node has choose the outgoing
1104 1117 * format based on the incoming request packet type. The assumption is