nfp: flower: handle ipv6 tunnel no neigh request
authorJohn Hurley <john.hurley@netronome.com>
Tue, 17 Dec 2019 21:57:21 +0000 (21:57 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Dec 2019 01:37:13 +0000 (17:37 -0800)
When fw does not know the next hop for an IPv6 tunnel, it sends a request
to the driver.

Handle this request by doing a route lookup on the IPv6 address and
offloading the next hop to the fw neighbour table.

Similar functions already exist to handle IPv4 no neighbour requests. To
avoid confusion, append these functions with the _ipv4 tag. There is no
change in functionality with this.

Signed-off-by: John Hurley <john.hurley@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/flower/cmsg.c
drivers/net/ethernet/netronome/nfp/flower/cmsg.h
drivers/net/ethernet/netronome/nfp/flower/main.h
drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c

index 05981b54eaab7dccd70d0f90dd90508c230481ad..00b904ea4ebc58b4e617bfde8572642719481a53 100644 (file)
@@ -270,7 +270,10 @@ nfp_flower_cmsg_process_one_rx(struct nfp_app *app, struct sk_buff *skb)
                }
                goto err_default;
        case NFP_FLOWER_CMSG_TYPE_NO_NEIGH:
-               nfp_tunnel_request_route(app, skb);
+               nfp_tunnel_request_route_v4(app, skb);
+               break;
+       case NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6:
+               nfp_tunnel_request_route_v6(app, skb);
                break;
        case NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS:
                nfp_tunnel_keep_alive(app, skb);
@@ -361,7 +364,8 @@ void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb)
                   nfp_flower_process_mtu_ack(app, skb)) {
                /* Handle MTU acks outside wq to prevent RTNL conflict. */
                dev_consume_skb_any(skb);
-       } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH) {
+       } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH ||
+                  cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6) {
                /* Acks from the NFP that the route is added - ignore. */
                dev_consume_skb_any(skb);
        } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_PORT_REIFY) {
index 7537695c233418238b77c4df090683099168f903..5a8ad5814060f2ca5b445b01b7c97462d283991d 100644 (file)
@@ -572,6 +572,8 @@ enum nfp_flower_cmsg_type_port {
        NFP_FLOWER_CMSG_TYPE_QOS_STATS =        20,
        NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE =     21,
        NFP_FLOWER_CMSG_TYPE_TUN_IPS_V6 =       22,
+       NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6 =      23,
+       NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6 =     24,
        NFP_FLOWER_CMSG_TYPE_MAX =              32,
 };
 
index bd288e236db785e70ce33a38a47997fe62bfba14..01e1886e9d85b7f449505970fb65c9edcb55cf9e 100644 (file)
@@ -418,7 +418,8 @@ void
 nfp_tunnel_put_ipv6_off(struct nfp_app *app, struct nfp_ipv6_addr_entry *entry);
 struct nfp_ipv6_addr_entry *
 nfp_tunnel_add_ipv6_off(struct nfp_app *app, struct in6_addr *ipv6);
-void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
+void nfp_tunnel_request_route_v4(struct nfp_app *app, struct sk_buff *skb);
+void nfp_tunnel_request_route_v6(struct nfp_app *app, struct sk_buff *skb);
 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
 void nfp_flower_lag_init(struct nfp_fl_lag *lag);
 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
index eddb52db6dce2f3712114ef4a586e09af43ad671..09807b31b830fd663a1a449b3bcb624b5add2274 100644 (file)
@@ -70,6 +70,22 @@ struct nfp_tun_neigh {
        __be32 port_id;
 };
 
+/**
+ * struct nfp_tun_neigh_v6 - neighbour/route entry on the NFP
+ * @dst_ipv6:  destination IPv6 address
+ * @src_ipv6:  source IPv6 address
+ * @dst_addr:  destination MAC address
+ * @src_addr:  source MAC address
+ * @port_id:   NFP port to output packet on - associated with source IPv6
+ */
+struct nfp_tun_neigh_v6 {
+       struct in6_addr dst_ipv6;
+       struct in6_addr src_ipv6;
+       u8 dst_addr[ETH_ALEN];
+       u8 src_addr[ETH_ALEN];
+       __be32 port_id;
+};
+
 /**
  * struct nfp_tun_req_route_ipv4 - NFP requests a route/neighbour lookup
  * @ingress_port:      ingress port of packet that signalled request
@@ -82,6 +98,16 @@ struct nfp_tun_req_route_ipv4 {
        __be32 reserved[2];
 };
 
+/**
+ * struct nfp_tun_req_route_ipv6 - NFP requests an IPv6 route/neighbour lookup
+ * @ingress_port:      ingress port of packet that signalled request
+ * @ipv6_addr:         destination ipv6 address for route
+ */
+struct nfp_tun_req_route_ipv6 {
+       __be32 ingress_port;
+       struct in6_addr ipv6_addr;
+};
+
 /**
  * struct nfp_ipv4_route_entry - routes that are offloaded to the NFP
  * @ipv4_addr: destination of route
@@ -299,8 +325,8 @@ static void nfp_tun_del_route_from_cache(struct nfp_app *app, __be32 ipv4_addr)
 }
 
 static void
-nfp_tun_write_neigh(struct net_device *netdev, struct nfp_app *app,
-                   struct flowi4 *flow, struct neighbour *neigh, gfp_t flag)
+nfp_tun_write_neigh_v4(struct net_device *netdev, struct nfp_app *app,
+                      struct flowi4 *flow, struct neighbour *neigh, gfp_t flag)
 {
        struct nfp_tun_neigh payload;
        u32 port_id;
@@ -334,6 +360,39 @@ send_msg:
                                 (unsigned char *)&payload, flag);
 }
 
+static void
+nfp_tun_write_neigh_v6(struct net_device *netdev, struct nfp_app *app,
+                      struct flowi6 *flow, struct neighbour *neigh, gfp_t flag)
+{
+       struct nfp_tun_neigh_v6 payload;
+       u32 port_id;
+
+       port_id = nfp_flower_get_port_id_from_netdev(app, netdev);
+       if (!port_id)
+               return;
+
+       memset(&payload, 0, sizeof(struct nfp_tun_neigh_v6));
+       payload.dst_ipv6 = flow->daddr;
+
+       /* If entry has expired send dst IP with all other fields 0. */
+       if (!(neigh->nud_state & NUD_VALID) || neigh->dead) {
+               /* Trigger probe to verify invalid neighbour state. */
+               neigh_event_send(neigh, NULL);
+               goto send_msg;
+       }
+
+       /* Have a valid neighbour so populate rest of entry. */
+       payload.src_ipv6 = flow->saddr;
+       ether_addr_copy(payload.src_addr, netdev->dev_addr);
+       neigh_ha_snapshot(payload.dst_addr, neigh, netdev);
+       payload.port_id = cpu_to_be32(port_id);
+
+send_msg:
+       nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6,
+                                sizeof(struct nfp_tun_neigh_v6),
+                                (unsigned char *)&payload, flag);
+}
+
 static int
 nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,
                            void *ptr)
@@ -384,12 +443,12 @@ nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,
 #endif
 
        flow.flowi4_proto = IPPROTO_UDP;
-       nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_ATOMIC);
+       nfp_tun_write_neigh_v4(n->dev, app, &flow, n, GFP_ATOMIC);
 
        return NOTIFY_OK;
 }
 
-void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb)
+void nfp_tunnel_request_route_v4(struct nfp_app *app, struct sk_buff *skb)
 {
        struct nfp_tun_req_route_ipv4 *payload;
        struct net_device *netdev;
@@ -423,7 +482,7 @@ void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb)
        ip_rt_put(rt);
        if (!n)
                goto fail_rcu_unlock;
-       nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_ATOMIC);
+       nfp_tun_write_neigh_v4(n->dev, app, &flow, n, GFP_ATOMIC);
        neigh_release(n);
        rcu_read_unlock();
        return;
@@ -433,6 +492,48 @@ fail_rcu_unlock:
        nfp_flower_cmsg_warn(app, "Requested route not found.\n");
 }
 
+void nfp_tunnel_request_route_v6(struct nfp_app *app, struct sk_buff *skb)
+{
+       struct nfp_tun_req_route_ipv6 *payload;
+       struct net_device *netdev;
+       struct flowi6 flow = {};
+       struct dst_entry *dst;
+       struct neighbour *n;
+
+       payload = nfp_flower_cmsg_get_data(skb);
+
+       rcu_read_lock();
+       netdev = nfp_app_dev_get(app, be32_to_cpu(payload->ingress_port), NULL);
+       if (!netdev)
+               goto fail_rcu_unlock;
+
+       flow.daddr = payload->ipv6_addr;
+       flow.flowi6_proto = IPPROTO_UDP;
+
+#if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
+       dst = ipv6_stub->ipv6_dst_lookup_flow(dev_net(netdev), NULL, &flow,
+                                             NULL);
+       if (IS_ERR(dst))
+               goto fail_rcu_unlock;
+#else
+       goto fail_rcu_unlock;
+#endif
+
+       n = dst_neigh_lookup(dst, &flow.daddr);
+       dst_release(dst);
+       if (!n)
+               goto fail_rcu_unlock;
+
+       nfp_tun_write_neigh_v6(n->dev, app, &flow, n, GFP_ATOMIC);
+       neigh_release(n);
+       rcu_read_unlock();
+       return;
+
+fail_rcu_unlock:
+       rcu_read_unlock();
+       nfp_flower_cmsg_warn(app, "Requested IPv6 route not found.\n");
+}
+
 static void nfp_tun_write_ipv4_list(struct nfp_app *app)
 {
        struct nfp_flower_priv *priv = app->priv;