Here, datapath support for setting nsh service index (nsi) is added.
nsi can now be set on outgoing packet depending on port settings or
set_nsi action.

Signed-off-by: Pritesh Kothari <pritesh.koth...@cisco.com>

diff --git a/datapath/datapath.c b/datapath/datapath.c
index b96ad1e..46a4f28 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -362,6 +362,7 @@ static size_t key_attr_size(void)
                  + nla_total_size(0)   /* OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT */
                  + nla_total_size(0)   /* OVS_TUNNEL_KEY_ATTR_CSUM */
                  + nla_total_size(4)   /* OVS_TUNNEL_KEY_ATTR_NSP */
+                 + nla_total_size(1)   /* OVS_TUNNEL_KEY_ATTR_NSI */
                + nla_total_size(4)   /* OVS_KEY_ATTR_IN_PORT */
                + nla_total_size(4)   /* OVS_KEY_ATTR_SKB_MARK */
                + nla_total_size(12)  /* OVS_KEY_ATTR_ETHERNET */
diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c
index a2bc1e9..8001aee 100644
--- a/datapath/flow_netlink.c
+++ b/datapath/flow_netlink.c
@@ -48,6 +48,8 @@
 
 #include "flow_netlink.h"
 
+#define NSH_M_NSI 0x000000FF
+
 static void update_range__(struct sw_flow_match *match,
                           size_t offset, size_t size, bool is_mask)
 {
@@ -346,6 +348,7 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                        [OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT] = 0,
                        [OVS_TUNNEL_KEY_ATTR_CSUM] = 0,
                        [OVS_TUNNEL_KEY_ATTR_NSP] = sizeof(u32),
+                       [OVS_TUNNEL_KEY_ATTR_NSI] = 1,
                };
 
                if (type > OVS_TUNNEL_KEY_ATTR_MAX) {
@@ -391,9 +394,13 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                        tun_flags |= TUNNEL_CSUM;
                        break;
                case OVS_TUNNEL_KEY_ATTR_NSP:
-                       nsp = htonl(be32_to_cpu(nla_get_be32(a)) << 8);
+                       nsp |= htonl(be32_to_cpu(nla_get_be32(a)) << 8);
                        tun_flags |= TUNNEL_NSP;
                        break;
+               case OVS_TUNNEL_KEY_ATTR_NSI:
+                       nsp |= htonl(nla_get_u8(a));
+                       tun_flags |= TUNNEL_NSI;
+                       break;
                default:
                        return -EINVAL;
                }
@@ -428,6 +435,7 @@ static int ipv4_tun_to_nlattr(struct sk_buff *skb,
 {
        struct nlattr *nla;
        __be32 nsp = cpu_to_be32(ntohl(output->nsp) >> 8);
+       u8 nsi = ntohl(output->nsp) & NSH_M_NSI;
 
        nla = nla_nest_start(skb, OVS_KEY_ATTR_TUNNEL);
        if (!nla)
@@ -456,6 +464,9 @@ static int ipv4_tun_to_nlattr(struct sk_buff *skb,
        if (output->tun_flags & TUNNEL_NSP &&
            nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_NSP, nsp))
                return -EMSGSIZE;
+       if (output->tun_flags & TUNNEL_NSI &&
+           nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_NSI, nsi))
+               return -EMSGSIZE;
 
        nla_nest_end(skb, nla);
        return 0;
diff --git a/datapath/linux/compat/include/net/ip_tunnels.h 
b/datapath/linux/compat/include/net/ip_tunnels.h
index a4aec4d..dfc1b59 100644
--- a/datapath/linux/compat/include/net/ip_tunnels.h
+++ b/datapath/linux/compat/include/net/ip_tunnels.h
@@ -21,6 +21,7 @@
 #define TUNNEL_NO_KEY  __cpu_to_be16(0x80)
 #define TUNNEL_DONT_FRAGMENT   __cpu_to_be16(0x0100)
 #define TUNNEL_NSP     __cpu_to_be16(0x0200)
+#define TUNNEL_NSI     __cpu_to_be16(0x0400)
 
 struct tnl_ptk_info {
        __be16 flags;
diff --git a/datapath/vport-vxlan.c b/datapath/vport-vxlan.c
index 999fdff..320e825 100644
--- a/datapath/vport-vxlan.c
+++ b/datapath/vport-vxlan.c
@@ -70,7 +70,7 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff 
*skb,
        iph = ip_hdr(skb);
        key = cpu_to_be64(ntohl(vx_vni) >> 8);
        ovs_flow_tun_key_init(&tun_key, iph, key, nsp,
-                             TUNNEL_KEY | TUNNEL_NSP);
+                             TUNNEL_KEY | TUNNEL_NSP | TUNNEL_NSI);
 
        ovs_vport_receive(vport, skb, &tun_key);
 }
diff --git a/include/linux/openvswitch.h b/include/linux/openvswitch.h
index 194acfe..bf95ce7 100644
--- a/include/linux/openvswitch.h
+++ b/include/linux/openvswitch.h
@@ -318,6 +318,12 @@ enum ovs_key_attr {
        __OVS_KEY_ATTR_MAX
 };
 
+/**
+ * OVS_TUNNEL_KEY_ATTR_NSI below can never be zero, because
+ * if it is zero the packet gets dropped, thus all outgoing
+ * packets have this defaulted to 1 if no outgoing value is
+ * explicitly set.
+ */
 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
 
 enum ovs_tunnel_key_attr {
@@ -329,6 +335,7 @@ enum ovs_tunnel_key_attr {
        OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT,      /* No argument, set DF. */
        OVS_TUNNEL_KEY_ATTR_CSUM,               /* No argument. CSUM packet. */
        OVS_TUNNEL_KEY_ATTR_NSP,                /* be32 NSH svc path (lower 24 
bits) */
+       OVS_TUNNEL_KEY_ATTR_NSI,                /* u8 NSH service index */
        __OVS_TUNNEL_KEY_ATTR_MAX
 };
 
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to