vxlan: minor output refactoring
[deliverable/linux.git] / drivers / net / vxlan.c
index f87a98f1aec248011dbfbc7dedad34512e47d682..92150c0cf4d9a3993cf25b96edb227696f3d8a6d 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/igmp.h>
 #include <linux/etherdevice.h>
 #include <linux/if_ether.h>
-#include <linux/version.h>
 #include <linux/hash.h>
 #include <net/ip.h>
 #include <net/icmp.h>
@@ -622,6 +621,22 @@ static inline u8 vxlan_ecn_encap(u8 tos,
        return INET_ECN_encapsulate(tos, inner);
 }
 
+static __be32 vxlan_find_dst(struct vxlan_dev *vxlan, struct sk_buff *skb)
+{
+       const struct ethhdr *eth = (struct ethhdr *) skb->data;
+       const struct vxlan_fdb *f;
+
+       if (is_multicast_ether_addr(eth->h_dest))
+               return vxlan->gaddr;
+
+       f = vxlan_find_mac(vxlan, eth->h_dest);
+       if (f)
+               return f->remote_ip;
+       else
+               return vxlan->gaddr;
+
+}
+
 /* Transmit local packets over Vxlan
  *
  * Outer IP header inherits ECN and DF from inner header.
@@ -633,13 +648,11 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct vxlan_dev *vxlan = netdev_priv(dev);
        struct rtable *rt;
-       const struct ethhdr *eth;
        const struct iphdr *old_iph;
        struct iphdr *iph;
        struct vxlanhdr *vxh;
        struct udphdr *uh;
        struct flowi4 fl4;
-       struct vxlan_fdb *f;
        unsigned int pkt_len = skb->len;
        u32 hash;
        __be32 dst;
@@ -647,21 +660,16 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
        __u8 tos, ttl;
        int err;
 
+       dst = vxlan_find_dst(vxlan, skb);
+       if (!dst)
+               goto drop;
+
        /* Need space for new headers (invalidates iph ptr) */
        if (skb_cow_head(skb, VXLAN_HEADROOM))
                goto drop;
 
-       eth = (void *)skb->data;
        old_iph = ip_hdr(skb);
 
-       if (!is_multicast_ether_addr(eth->h_dest) &&
-           (f = vxlan_find_mac(vxlan, eth->h_dest)))
-               dst = f->remote_ip;
-       else if (vxlan->gaddr) {
-               dst = vxlan->gaddr;
-       } else
-               goto drop;
-
        ttl = vxlan->ttl;
        if (!ttl && IN_MULTICAST(ntohl(dst)))
                ttl = 1;
@@ -1084,13 +1092,13 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
        if (nla_put_u32(skb, IFLA_VXLAN_ID, vxlan->vni))
                goto nla_put_failure;
 
-       if (vxlan->gaddr && nla_put_u32(skb, IFLA_VXLAN_GROUP, vxlan->gaddr))
+       if (vxlan->gaddr && nla_put_be32(skb, IFLA_VXLAN_GROUP, vxlan->gaddr))
                goto nla_put_failure;
 
        if (vxlan->link && nla_put_u32(skb, IFLA_VXLAN_LINK, vxlan->link))
                goto nla_put_failure;
 
-       if (vxlan->saddr && nla_put_u32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr))
+       if (vxlan->saddr && nla_put_be32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr))
                goto nla_put_failure;
 
        if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->ttl) ||
@@ -1136,6 +1144,9 @@ static __net_init int vxlan_init_net(struct net *net)
                pr_debug("UDP socket create failed\n");
                return rc;
        }
+       /* Put in proper namespace */
+       sk = vn->sock->sk;
+       sk_change_net(sk, net);
 
        vxlan_addr.sin_port = htons(vxlan_port);
 
@@ -1144,13 +1155,12 @@ static __net_init int vxlan_init_net(struct net *net)
        if (rc < 0) {
                pr_debug("bind for UDP socket %pI4:%u (%d)\n",
                         &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc);
-               sock_release(vn->sock);
+               sk_release_kernel(sk);
                vn->sock = NULL;
                return rc;
        }
 
        /* Disable multicast loopback */
-       sk = vn->sock->sk;
        inet_sk(sk)->mc_loop = 0;
 
        /* Mark socket as an encapsulation socket. */
@@ -1169,7 +1179,7 @@ static __net_exit void vxlan_exit_net(struct net *net)
        struct vxlan_net *vn = net_generic(net, vxlan_net_id);
 
        if (vn->sock) {
-               sock_release(vn->sock);
+               sk_release_kernel(vn->sock->sk);
                vn->sock = NULL;
        }
 }
This page took 0.026763 seconds and 5 git commands to generate.