[ovs-dev] [PATCH v3, 2/7] lib: rename ovs_nd_opt to ovs_nd_lla_opt

Zongkai LI zealokii at gmail.com
Fri Oct 14 03:57:16 UTC 2016


Since ovs_nd_mtu_opt and ovs_nd_prefix_opt is introducted, rename
ovs_nd_opt to ovs_nd_lla_opt to specify it's Source/Target Link-layer
Address Option.

Signed-off-by: Zongkai LI <zealokii at gmail.com>
---
 lib/flow.c        | 30 +++++++++++------------
 lib/odp-execute.c | 22 ++++++++---------
 lib/packets.c     | 72 +++++++++++++++++++++++++++----------------------------
 lib/packets.h     | 19 +++++++--------
 4 files changed, 71 insertions(+), 72 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index f4ac8b3..bf1b2f1 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -400,8 +400,8 @@ parse_icmpv6(const void **datap, size_t *sizep, const struct icmp6_hdr *icmp,
         while (*sizep >= 8) {
             /* The minimum size of an option is 8 bytes, which also is
              * the size of Ethernet link-layer options. */
-            const struct ovs_nd_opt *nd_opt = *datap;
-            int opt_len = nd_opt->nd_opt_len * ND_OPT_LEN;
+            const struct ovs_nd_lla_opt *lla_opt = *datap;
+            int opt_len = lla_opt->len * ND_LLA_OPT_LEN;
 
             if (!opt_len || opt_len > *sizep) {
                 return;
@@ -410,17 +410,17 @@ parse_icmpv6(const void **datap, size_t *sizep, const struct icmp6_hdr *icmp,
             /* Store the link layer address if the appropriate option is
              * provided.  It is considered an error if the same link
              * layer option is specified twice. */
-            if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
+            if (lla_opt->type == ND_OPT_SOURCE_LINKADDR
                 && opt_len == 8) {
                 if (OVS_LIKELY(eth_addr_is_zero(arp_buf[0]))) {
-                    arp_buf[0] = nd_opt->nd_opt_mac;
+                    arp_buf[0] = lla_opt->mac;
                 } else {
                     goto invalid;
                 }
-            } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
+            } else if (lla_opt->type == ND_OPT_TARGET_LINKADDR
                        && opt_len == 8) {
                 if (OVS_LIKELY(eth_addr_is_zero(arp_buf[1]))) {
-                    arp_buf[1] = nd_opt->nd_opt_mac;
+                    arp_buf[1] = lla_opt->mac;
                 } else {
                     goto invalid;
                 }
@@ -2274,7 +2274,7 @@ flow_compose_l4(struct dp_packet *p, const struct flow *flow)
                 (icmp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
                  icmp->icmp6_type == ND_NEIGHBOR_ADVERT)) {
                 struct in6_addr *nd_target;
-                struct ovs_nd_opt *nd_opt;
+                struct ovs_nd_lla_opt *lla_opt;
 
                 l4_len += sizeof *nd_target;
                 nd_target = dp_packet_put_zeros(p, sizeof *nd_target);
@@ -2282,17 +2282,17 @@ flow_compose_l4(struct dp_packet *p, const struct flow *flow)
 
                 if (!eth_addr_is_zero(flow->arp_sha)) {
                     l4_len += 8;
-                    nd_opt = dp_packet_put_zeros(p, 8);
-                    nd_opt->nd_opt_len = 1;
-                    nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
-                    nd_opt->nd_opt_mac = flow->arp_sha;
+                    lla_opt = dp_packet_put_zeros(p, 8);
+                    lla_opt->len = 1;
+                    lla_opt->type = ND_OPT_SOURCE_LINKADDR;
+                    lla_opt->mac = flow->arp_sha;
                 }
                 if (!eth_addr_is_zero(flow->arp_tha)) {
                     l4_len += 8;
-                    nd_opt = dp_packet_put_zeros(p, 8);
-                    nd_opt->nd_opt_len = 1;
-                    nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
-                    nd_opt->nd_opt_mac = flow->arp_tha;
+                    lla_opt = dp_packet_put_zeros(p, 8);
+                    lla_opt->len = 1;
+                    lla_opt->type = ND_OPT_TARGET_LINKADDR;
+                    lla_opt->mac = flow->arp_tha;
                 }
             }
         }
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index 65a6fcd..9c66de7 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -185,33 +185,33 @@ odp_set_nd(struct dp_packet *packet, const struct ovs_key_nd *key,
            const struct ovs_key_nd *mask)
 {
     const struct ovs_nd_msg *ns = dp_packet_l4(packet);
-    const struct ovs_nd_opt *nd_opt = dp_packet_get_nd_payload(packet);
+    const struct ovs_nd_lla_opt *lla_opt = dp_packet_get_nd_payload(packet);
 
-    if (OVS_LIKELY(ns && nd_opt)) {
+    if (OVS_LIKELY(ns && lla_opt)) {
         int bytes_remain = dp_packet_l4_size(packet) - sizeof(*ns);
         ovs_be32 tgt_buf[4];
         struct eth_addr sll_buf = eth_addr_zero;
         struct eth_addr tll_buf = eth_addr_zero;
 
-        while (bytes_remain >= ND_OPT_LEN && nd_opt->nd_opt_len != 0) {
-            if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
-                && nd_opt->nd_opt_len == 1) {
-                sll_buf = nd_opt->nd_opt_mac;
+        while (bytes_remain >= ND_LLA_OPT_LEN && lla_opt->len != 0) {
+            if (lla_opt->type == ND_OPT_SOURCE_LINKADDR
+                && lla_opt->len == 1) {
+                sll_buf = lla_opt->mac;
                 ether_addr_copy_masked(&sll_buf, key->nd_sll, mask->nd_sll);
 
                 /* A packet can only contain one SLL or TLL option */
                 break;
-            } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
-                       && nd_opt->nd_opt_len == 1) {
-                tll_buf = nd_opt->nd_opt_mac;
+            } else if (lla_opt->type == ND_OPT_TARGET_LINKADDR
+                       && lla_opt->len == 1) {
+                tll_buf = lla_opt->mac;
                 ether_addr_copy_masked(&tll_buf, key->nd_tll, mask->nd_tll);
 
                 /* A packet can only contain one SLL or TLL option */
                 break;
             }
 
-            nd_opt += nd_opt->nd_opt_len;
-            bytes_remain -= nd_opt->nd_opt_len * ND_OPT_LEN;
+            lla_opt += lla_opt->len;
+            bytes_remain -= lla_opt->len * ND_LLA_OPT_LEN;
         }
 
         packet_set_nd(packet,
diff --git a/lib/packets.c b/lib/packets.c
index 7557e76..6ebd038 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -1163,7 +1163,7 @@ packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
               const struct eth_addr sll, const struct eth_addr tll)
 {
     struct ovs_nd_msg *ns;
-    struct ovs_nd_opt *nd_opt;
+    struct ovs_nd_lla_opt *lla_opt;
     int bytes_remain = dp_packet_l4_size(packet);
 
     if (OVS_UNLIKELY(bytes_remain < sizeof(*ns))) {
@@ -1171,7 +1171,7 @@ packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
     }
 
     ns = dp_packet_l4(packet);
-    nd_opt = &ns->options[0];
+    lla_opt = &ns->options[0];
     bytes_remain -= sizeof(*ns);
 
     if (memcmp(&ns->target, target, sizeof(ovs_be32[4]))) {
@@ -1180,33 +1180,33 @@ packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
                              target, true);
     }
 
-    while (bytes_remain >= ND_OPT_LEN && nd_opt->nd_opt_len != 0) {
-        if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
-            && nd_opt->nd_opt_len == 1) {
-            if (!eth_addr_equals(nd_opt->nd_opt_mac, sll)) {
+    while (bytes_remain >= ND_LLA_OPT_LEN && lla_opt->len != 0) {
+        if (lla_opt->type == ND_OPT_SOURCE_LINKADDR
+            && lla_opt->len == 1) {
+            if (!eth_addr_equals(lla_opt->mac, sll)) {
                 ovs_be16 *csum = &(ns->icmph.icmp6_cksum);
 
-                *csum = recalc_csum48(*csum, nd_opt->nd_opt_mac, sll);
-                nd_opt->nd_opt_mac = sll;
+                *csum = recalc_csum48(*csum, lla_opt->mac, sll);
+                lla_opt->mac = sll;
             }
 
             /* A packet can only contain one SLL or TLL option */
             break;
-        } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
-                   && nd_opt->nd_opt_len == 1) {
-            if (!eth_addr_equals(nd_opt->nd_opt_mac, tll)) {
+        } else if (lla_opt->type == ND_OPT_TARGET_LINKADDR
+                   && lla_opt->len == 1) {
+            if (!eth_addr_equals(lla_opt->mac, tll)) {
                 ovs_be16 *csum = &(ns->icmph.icmp6_cksum);
 
-                *csum = recalc_csum48(*csum, nd_opt->nd_opt_mac, tll);
-                nd_opt->nd_opt_mac = tll;
+                *csum = recalc_csum48(*csum, lla_opt->mac, tll);
+                lla_opt->mac = tll;
             }
 
             /* A packet can only contain one SLL or TLL option */
             break;
         }
 
-        nd_opt += nd_opt->nd_opt_len;
-        bytes_remain -= nd_opt->nd_opt_len * ND_OPT_LEN;
+        lla_opt += lla_opt->len;
+        bytes_remain -= lla_opt->len * ND_LLA_OPT_LEN;
     }
 }
 
@@ -1377,7 +1377,7 @@ compose_nd_ns(struct dp_packet *b, const struct eth_addr eth_src,
     struct in6_addr sn_addr;
     struct eth_addr eth_dst;
     struct ovs_nd_msg *ns;
-    struct ovs_nd_opt *nd_opt;
+    struct ovs_nd_lla_opt *lla_opt;
     uint32_t icmp_csum;
 
     in6_addr_solicited_node(&sn_addr, ipv6_dst);
@@ -1385,15 +1385,15 @@ compose_nd_ns(struct dp_packet *b, const struct eth_addr eth_src,
 
     eth_compose(b, eth_dst, eth_src, ETH_TYPE_IPV6, IPV6_HEADER_LEN);
     ns = compose_ipv6(b, IPPROTO_ICMPV6, ipv6_src, &sn_addr,
-                      0, 0, 255, ND_MSG_LEN + ND_OPT_LEN);
+                      0, 0, 255, ND_MSG_LEN + ND_LLA_OPT_LEN);
 
     ns->icmph.icmp6_type = ND_NEIGHBOR_SOLICIT;
     ns->icmph.icmp6_code = 0;
     put_16aligned_be32(&ns->rso_flags, htonl(0));
 
-    nd_opt = &ns->options[0];
-    nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
-    nd_opt->nd_opt_len = 1;
+    lla_opt = &ns->options[0];
+    lla_opt->type = ND_OPT_SOURCE_LINKADDR;
+    lla_opt->len = 1;
 
     /* Copy target address to temp buffer to prevent misaligned access. */
     ovs_be32 tbuf[4];
@@ -1402,8 +1402,8 @@ compose_nd_ns(struct dp_packet *b, const struct eth_addr eth_src,
 
     ns->icmph.icmp6_cksum = 0;
     icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
-    ns->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ns,
-                                                      ND_MSG_LEN + ND_OPT_LEN));
+    ns->icmph.icmp6_cksum = csum_finish(
+        csum_continue(icmp_csum, ns, ND_MSG_LEN + ND_LLA_OPT_LEN));
 }
 
 /* Compose an IPv6 Neighbor Discovery Neighbor Advertisement message. */
@@ -1414,20 +1414,20 @@ compose_nd_na(struct dp_packet *b,
               ovs_be32 rso_flags)
 {
     struct ovs_nd_msg *na;
-    struct ovs_nd_opt *nd_opt;
+    struct ovs_nd_lla_opt *lla_opt;
     uint32_t icmp_csum;
 
     eth_compose(b, eth_dst, eth_src, ETH_TYPE_IPV6, IPV6_HEADER_LEN);
     na = compose_ipv6(b, IPPROTO_ICMPV6, ipv6_src, ipv6_dst,
-                      0, 0, 255, ND_MSG_LEN + ND_OPT_LEN);
+                      0, 0, 255, ND_MSG_LEN + ND_LLA_OPT_LEN);
 
     na->icmph.icmp6_type = ND_NEIGHBOR_ADVERT;
     na->icmph.icmp6_code = 0;
     put_16aligned_be32(&na->rso_flags, rso_flags);
 
-    nd_opt = &na->options[0];
-    nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
-    nd_opt->nd_opt_len = 1;
+    lla_opt = &na->options[0];
+    lla_opt->type = ND_OPT_TARGET_LINKADDR;
+    lla_opt->len = 1;
 
     /* Copy target address to temp buffer to prevent misaligned access. */
     ovs_be32 tbuf[4];
@@ -1436,8 +1436,8 @@ compose_nd_na(struct dp_packet *b,
 
     na->icmph.icmp6_cksum = 0;
     icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
-    na->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, na,
-                                                      ND_MSG_LEN + ND_OPT_LEN));
+    na->icmph.icmp6_cksum = csum_finish(csum_continue(
+        icmp_csum, na, ND_MSG_LEN + ND_LLA_OPT_LEN));
 }
 
 /* Compose an IPv6 Neighbor Discovery Router Advertisement message with
@@ -1455,8 +1455,8 @@ compose_nd_ra_with_sll_mtu_opts(struct dp_packet *b,
                                 ovs_be32 retrans_timer, ovs_be32 mtu)
 {
     struct ovs_ra_msg *ra;
+    struct ovs_nd_lla_opt *lla_opt;
     struct ovs_nd_mtu_opt *mtu_opt;
-    struct ovs_nd_opt *lla_opt;
     uint32_t icmp_csum;
 
     /* Don't compose Router Advertisement packet with MTU Option if mtu
@@ -1466,7 +1466,7 @@ compose_nd_ra_with_sll_mtu_opts(struct dp_packet *b,
 
     eth_compose(b, eth_dst, eth_src, ETH_TYPE_IPV6, IPV6_HEADER_LEN);
     ra = compose_ipv6(b, IPPROTO_ICMPV6, ipv6_src, ipv6_dst, 0, 0, 255,
-                      RA_MSG_LEN + ND_OPT_LEN + mtu_opt_len);
+                      RA_MSG_LEN + ND_LLA_OPT_LEN + mtu_opt_len);
 
     ra->icmph.icmp6_type = ND_ROUTER_ADVERT;
     ra->icmph.icmp6_code = 0;
@@ -1477,12 +1477,12 @@ compose_nd_ra_with_sll_mtu_opts(struct dp_packet *b,
     ra->retrans_timer = retrans_timer;
 
     lla_opt = &ra->options[0];
-    lla_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
-    lla_opt->nd_opt_len = 1;
-    lla_opt->nd_opt_mac = eth_src;
+    lla_opt->type = ND_OPT_SOURCE_LINKADDR;
+    lla_opt->len = 1;
+    lla_opt->mac = eth_src;
 
     if (with_mtu) {
-        /* ovs_nd_mtu_opt has the same size with ovs_nd_opt. */
+        /* ovs_nd_mtu_opt has the same size with ovs_nd_lla_opt. */
         mtu_opt = (struct ovs_nd_mtu_opt *)(lla_opt + 1);
         mtu_opt->type = ND_OPT_MTU;
         mtu_opt->len = 1;
@@ -1493,7 +1493,7 @@ compose_nd_ra_with_sll_mtu_opts(struct dp_packet *b,
     ra->icmph.icmp6_cksum = 0;
     icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
     ra->icmph.icmp6_cksum = csum_finish(csum_continue(
-        icmp_csum, ra, RA_MSG_LEN + ND_OPT_LEN + mtu_opt_len));
+        icmp_csum, ra, RA_MSG_LEN + ND_LLA_OPT_LEN + mtu_opt_len));
 }
 
 /* Append an IPv6 Neighbor Discovery Prefix Information option to a
diff --git a/lib/packets.h b/lib/packets.h
index 337ddf6..b70bb12 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -841,15 +841,14 @@ BUILD_ASSERT_DECL(ICMP6_HEADER_LEN == sizeof(struct icmp6_header));
 
 uint32_t packet_csum_pseudoheader6(const struct ovs_16aligned_ip6_hdr *);
 
-/* Neighbor Discovery option field.
- * ND options are always a multiple of 8 bytes in size. */
-#define ND_OPT_LEN 8
-struct ovs_nd_opt {
-    uint8_t  nd_opt_type;      /* Values defined in icmp6.h */
-    uint8_t  nd_opt_len;       /* in units of 8 octets (the size of this struct) */
-    struct eth_addr nd_opt_mac;   /* Ethernet address in the case of SLL or TLL options */
+/* Neighbor Discovery option: Source/Target Link-layer Address. */
+#define ND_LLA_OPT_LEN 8
+struct ovs_nd_lla_opt {
+    uint8_t  type;      /* Values defined in icmp6.h */
+    uint8_t  len;       /* in units of 8 octets (the size of this struct) */
+    struct eth_addr mac;   /* Ethernet address in the case of SLL or TLL options */
 };
-BUILD_ASSERT_DECL(ND_OPT_LEN == sizeof(struct ovs_nd_opt));
+BUILD_ASSERT_DECL(ND_LLA_OPT_LEN == sizeof(struct ovs_nd_lla_opt));
 
 /* Neighbor Discovery option: Prefix Information. */
 #define ND_PREFIX_OPT_LEN 32
@@ -885,7 +884,7 @@ struct ovs_nd_msg {
     struct icmp6_header icmph;
     ovs_16aligned_be32 rso_flags;
     union ovs_16aligned_in6_addr target;
-    struct ovs_nd_opt options[0];
+    struct ovs_nd_lla_opt options[0];
 };
 BUILD_ASSERT_DECL(ND_MSG_LEN == sizeof(struct ovs_nd_msg));
 
@@ -902,7 +901,7 @@ struct ovs_ra_msg {
     ovs_be16 router_lifetime;
     ovs_be32 reachable_time;
     ovs_be32 retrans_timer;
-    struct ovs_nd_opt options[0];
+    struct ovs_nd_lla_opt options[0];
 };
 BUILD_ASSERT_DECL(RA_MSG_LEN == sizeof(struct ovs_ra_msg));
 
-- 
2.7.4




More information about the dev mailing list