aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorAlexander Duyck <aduyck@mirantis.com>2016-06-16 15:20:52 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-17 23:23:29 -0400
commite7b3db5e60e8f471c3f5ef93b497bafe5863e56a (patch)
tree7cc8ee25fc39778069825cc8b87de542d7938d3e /net/ipv4
parent86a98057256020e75e1be0f88d7617491a06e8f1 (diff)
net: Combine GENEVE and VXLAN port notifiers into single functions
This patch merges the GENEVE and VXLAN code so that both functions pass through a shared code path. This way we can start the effort of using a single function on the network device drivers to handle both of these tunnel types. Signed-off-by: Alexander Duyck <aduyck@mirantis.com> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/udp_tunnel.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c
index 47f12c73d959..8174753e6494 100644
--- a/net/ipv4/udp_tunnel.c
+++ b/net/ipv4/udp_tunnel.c
@@ -76,6 +76,108 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
76} 76}
77EXPORT_SYMBOL_GPL(setup_udp_tunnel_sock); 77EXPORT_SYMBOL_GPL(setup_udp_tunnel_sock);
78 78
79static void __udp_tunnel_push_rx_port(struct net_device *dev,
80 struct udp_tunnel_info *ti)
81{
82 switch (ti->type) {
83 case UDP_TUNNEL_TYPE_VXLAN:
84 if (!dev->netdev_ops->ndo_add_vxlan_port)
85 break;
86
87 dev->netdev_ops->ndo_add_vxlan_port(dev,
88 ti->sa_family,
89 ti->port);
90 break;
91 case UDP_TUNNEL_TYPE_GENEVE:
92 if (!dev->netdev_ops->ndo_add_geneve_port)
93 break;
94
95 dev->netdev_ops->ndo_add_geneve_port(dev,
96 ti->sa_family,
97 ti->port);
98 break;
99 default:
100 break;
101 }
102}
103
104void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
105 unsigned short type)
106{
107 struct sock *sk = sock->sk;
108 struct udp_tunnel_info ti;
109
110 ti.type = type;
111 ti.sa_family = sk->sk_family;
112 ti.port = inet_sk(sk)->inet_sport;
113
114 __udp_tunnel_push_rx_port(dev, &ti);
115}
116EXPORT_SYMBOL_GPL(udp_tunnel_push_rx_port);
117
118/* Notify netdevs that UDP port started listening */
119void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type)
120{
121 struct sock *sk = sock->sk;
122 struct net *net = sock_net(sk);
123 struct udp_tunnel_info ti;
124 struct net_device *dev;
125
126 ti.type = type;
127 ti.sa_family = sk->sk_family;
128 ti.port = inet_sk(sk)->inet_sport;
129
130 rcu_read_lock();
131 for_each_netdev_rcu(net, dev)
132 __udp_tunnel_push_rx_port(dev, &ti);
133 rcu_read_unlock();
134}
135EXPORT_SYMBOL_GPL(udp_tunnel_notify_add_rx_port);
136
137static void __udp_tunnel_pull_rx_port(struct net_device *dev,
138 struct udp_tunnel_info *ti)
139{
140 switch (ti->type) {
141 case UDP_TUNNEL_TYPE_VXLAN:
142 if (!dev->netdev_ops->ndo_del_vxlan_port)
143 break;
144
145 dev->netdev_ops->ndo_del_vxlan_port(dev,
146 ti->sa_family,
147 ti->port);
148 break;
149 case UDP_TUNNEL_TYPE_GENEVE:
150 if (!dev->netdev_ops->ndo_del_geneve_port)
151 break;
152
153 dev->netdev_ops->ndo_del_geneve_port(dev,
154 ti->sa_family,
155 ti->port);
156 break;
157 default:
158 break;
159 }
160}
161
162/* Notify netdevs that UDP port is no more listening */
163void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type)
164{
165 struct sock *sk = sock->sk;
166 struct net *net = sock_net(sk);
167 struct udp_tunnel_info ti;
168 struct net_device *dev;
169
170 ti.type = type;
171 ti.sa_family = sk->sk_family;
172 ti.port = inet_sk(sk)->inet_sport;
173
174 rcu_read_lock();
175 for_each_netdev_rcu(net, dev)
176 __udp_tunnel_pull_rx_port(dev, &ti);
177 rcu_read_unlock();
178}
179EXPORT_SYMBOL_GPL(udp_tunnel_notify_del_rx_port);
180
79void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb, 181void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
80 __be32 src, __be32 dst, __u8 tos, __u8 ttl, 182 __be32 src, __be32 dst, __u8 tos, __u8 ttl,
81 __be16 df, __be16 src_port, __be16 dst_port, 183 __be16 df, __be16 src_port, __be16 dst_port,