Commit 4b5f6723 authored by Martin Varghese's avatar Martin Varghese Committed by David S. Miller

net: Special handling for IP & MPLS.

Special handling is needed in bareudp module for IP & MPLS as they
support more than one ethertypes.

MPLS has 2 ethertypes. 0x8847 for MPLS unicast and 0x8848 for MPLS multicast.
While decapsulating MPLS packet from UDP packet the tunnel destination IP
address is checked to determine the ethertype. The ethertype of the packet
will be set to 0x8848 if the  tunnel destination IP address is a multicast
IP address. The ethertype of the packet will be set to 0x8847 if the
tunnel destination IP address is a unicast IP address.

IP has 2 ethertypes.0x0800 for IPV4 and 0x86dd for IPv6. The version
field of the IP header tunnelled will be checked to determine the ethertype.

This special handling to tunnel additional ethertypes will be disabled
by default and can be enabled using a flag called multiproto. This flag can
be used only with ethertypes 0x8847 and 0x0800.
Signed-off-by: default avatarMartin Varghese <martin.varghese@nokia.com>
Acked-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 571912c6
...@@ -12,6 +12,15 @@ The Bareudp tunnel module provides a generic L3 encapsulation tunnelling ...@@ -12,6 +12,15 @@ The Bareudp tunnel module provides a generic L3 encapsulation tunnelling
support for tunnelling different L3 protocols like MPLS, IP, NSH etc. inside support for tunnelling different L3 protocols like MPLS, IP, NSH etc. inside
a UDP tunnel. a UDP tunnel.
Special Handling
----------------
The bareudp device supports special handling for MPLS & IP as they can have
multiple ethertypes.
MPLS procotcol can have ethertypes ETH_P_MPLS_UC (unicast) & ETH_P_MPLS_MC (multicast).
IP protocol can have ethertypes ETH_P_IP (v4) & ETH_P_IPV6 (v6).
This special handling can be enabled only for ethertypes ETH_P_IP & ETH_P_MPLS_UC
with a flag called multiproto mode.
Usage Usage
------ ------
...@@ -25,7 +34,16 @@ Usage ...@@ -25,7 +34,16 @@ Usage
b) ip link delete bareudp0 b) ip link delete bareudp0
2) Device Usage 2) Device creation with multiple proto mode enabled
There are two ways to create a bareudp device for MPLS & IP with multiproto mode
enabled.
a) ip link add dev bareudp0 type bareudp dstport 6635 ethertype 0x8847 multiproto
b) ip link add dev bareudp0 type bareudp dstport 6635 ethertype mpls
3) Device Usage
The bareudp device could be used along with OVS or flower filter in TC. The bareudp device could be used along with OVS or flower filter in TC.
The OVS or TC flower layer must set the tunnel information in SKB dst field before The OVS or TC flower layer must set the tunnel information in SKB dst field before
......
...@@ -45,6 +45,7 @@ struct bareudp_dev { ...@@ -45,6 +45,7 @@ struct bareudp_dev {
__be16 ethertype; __be16 ethertype;
__be16 port; __be16 port;
u16 sport_min; u16 sport_min;
bool multi_proto_mode;
struct socket __rcu *sock; struct socket __rcu *sock;
struct list_head next; /* bareudp node on namespace list */ struct list_head next; /* bareudp node on namespace list */
struct gro_cells gro_cells; struct gro_cells gro_cells;
...@@ -70,7 +71,52 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -70,7 +71,52 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
else else
family = AF_INET6; family = AF_INET6;
if (bareudp->ethertype == htons(ETH_P_IP)) {
struct iphdr *iphdr;
iphdr = (struct iphdr *)(skb->data + BAREUDP_BASE_HLEN);
if (iphdr->version == 4) {
proto = bareudp->ethertype;
} else if (bareudp->multi_proto_mode && (iphdr->version == 6)) {
proto = htons(ETH_P_IPV6);
} else {
bareudp->dev->stats.rx_dropped++;
goto drop;
}
} else if (bareudp->ethertype == htons(ETH_P_MPLS_UC)) {
struct iphdr *tunnel_hdr;
tunnel_hdr = (struct iphdr *)skb_network_header(skb);
if (tunnel_hdr->version == 4) {
if (!ipv4_is_multicast(tunnel_hdr->daddr)) {
proto = bareudp->ethertype;
} else if (bareudp->multi_proto_mode &&
ipv4_is_multicast(tunnel_hdr->daddr)) {
proto = htons(ETH_P_MPLS_MC);
} else {
bareudp->dev->stats.rx_dropped++;
goto drop;
}
} else {
int addr_type;
struct ipv6hdr *tunnel_hdr_v6;
tunnel_hdr_v6 = (struct ipv6hdr *)skb_network_header(skb);
addr_type =
ipv6_addr_type((struct in6_addr *)&tunnel_hdr_v6->daddr);
if (!(addr_type & IPV6_ADDR_MULTICAST)) {
proto = bareudp->ethertype; proto = bareudp->ethertype;
} else if (bareudp->multi_proto_mode &&
(addr_type & IPV6_ADDR_MULTICAST)) {
proto = htons(ETH_P_MPLS_MC);
} else {
bareudp->dev->stats.rx_dropped++;
goto drop;
}
}
} else {
proto = bareudp->ethertype;
}
if (iptunnel_pull_header(skb, BAREUDP_BASE_HLEN, if (iptunnel_pull_header(skb, BAREUDP_BASE_HLEN,
proto, proto,
...@@ -369,9 +415,13 @@ static netdev_tx_t bareudp_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -369,9 +415,13 @@ static netdev_tx_t bareudp_xmit(struct sk_buff *skb, struct net_device *dev)
int err; int err;
if (skb->protocol != bareudp->ethertype) { if (skb->protocol != bareudp->ethertype) {
if (!bareudp->multi_proto_mode ||
(skb->protocol != htons(ETH_P_MPLS_MC) &&
skb->protocol != htons(ETH_P_IPV6))) {
err = -EINVAL; err = -EINVAL;
goto tx_error; goto tx_error;
} }
}
info = skb_tunnel_info(skb); info = skb_tunnel_info(skb);
if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
...@@ -463,6 +513,7 @@ static const struct nla_policy bareudp_policy[IFLA_BAREUDP_MAX + 1] = { ...@@ -463,6 +513,7 @@ static const struct nla_policy bareudp_policy[IFLA_BAREUDP_MAX + 1] = {
[IFLA_BAREUDP_PORT] = { .type = NLA_U16 }, [IFLA_BAREUDP_PORT] = { .type = NLA_U16 },
[IFLA_BAREUDP_ETHERTYPE] = { .type = NLA_U16 }, [IFLA_BAREUDP_ETHERTYPE] = { .type = NLA_U16 },
[IFLA_BAREUDP_SRCPORT_MIN] = { .type = NLA_U16 }, [IFLA_BAREUDP_SRCPORT_MIN] = { .type = NLA_U16 },
[IFLA_BAREUDP_MULTIPROTO_MODE] = { .type = NLA_FLAG },
}; };
/* Info for udev, that this is a virtual tunnel endpoint */ /* Info for udev, that this is a virtual tunnel endpoint */
...@@ -545,9 +596,15 @@ static int bareudp_configure(struct net *net, struct net_device *dev, ...@@ -545,9 +596,15 @@ static int bareudp_configure(struct net *net, struct net_device *dev,
if (t) if (t)
return -EBUSY; return -EBUSY;
if (conf->multi_proto_mode &&
(conf->ethertype != htons(ETH_P_MPLS_UC) &&
conf->ethertype != htons(ETH_P_IP)))
return -EINVAL;
bareudp->port = conf->port; bareudp->port = conf->port;
bareudp->ethertype = conf->ethertype; bareudp->ethertype = conf->ethertype;
bareudp->sport_min = conf->sport_min; bareudp->sport_min = conf->sport_min;
bareudp->multi_proto_mode = conf->multi_proto_mode;
err = register_netdevice(dev); err = register_netdevice(dev);
if (err) if (err)
return err; return err;
...@@ -604,6 +661,7 @@ static size_t bareudp_get_size(const struct net_device *dev) ...@@ -604,6 +661,7 @@ static size_t bareudp_get_size(const struct net_device *dev)
return nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_PORT */ return nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_PORT */
nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_ETHERTYPE */ nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_ETHERTYPE */
nla_total_size(sizeof(__u16)) + /* IFLA_BAREUDP_SRCPORT_MIN */ nla_total_size(sizeof(__u16)) + /* IFLA_BAREUDP_SRCPORT_MIN */
nla_total_size(0) + /* IFLA_BAREUDP_MULTIPROTO_MODE */
0; 0;
} }
...@@ -617,6 +675,9 @@ static int bareudp_fill_info(struct sk_buff *skb, const struct net_device *dev) ...@@ -617,6 +675,9 @@ static int bareudp_fill_info(struct sk_buff *skb, const struct net_device *dev)
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u16(skb, IFLA_BAREUDP_SRCPORT_MIN, bareudp->sport_min)) if (nla_put_u16(skb, IFLA_BAREUDP_SRCPORT_MIN, bareudp->sport_min))
goto nla_put_failure; goto nla_put_failure;
if (bareudp->multi_proto_mode &&
nla_put_flag(skb, IFLA_BAREUDP_MULTIPROTO_MODE))
goto nla_put_failure;
return 0; return 0;
......
...@@ -10,6 +10,7 @@ struct bareudp_conf { ...@@ -10,6 +10,7 @@ struct bareudp_conf {
__be16 ethertype; __be16 ethertype;
__be16 port; __be16 port;
u16 sport_min; u16 sport_min;
bool multi_proto_mode;
}; };
struct net_device *bareudp_dev_create(struct net *net, const char *name, struct net_device *bareudp_dev_create(struct net *net, const char *name,
......
...@@ -596,6 +596,7 @@ enum { ...@@ -596,6 +596,7 @@ enum {
IFLA_BAREUDP_PORT, IFLA_BAREUDP_PORT,
IFLA_BAREUDP_ETHERTYPE, IFLA_BAREUDP_ETHERTYPE,
IFLA_BAREUDP_SRCPORT_MIN, IFLA_BAREUDP_SRCPORT_MIN,
IFLA_BAREUDP_MULTIPROTO_MODE,
__IFLA_BAREUDP_MAX __IFLA_BAREUDP_MAX
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment