]> Pileus Git - ~andy/linux/blobdiff - net/ipv4/ipip.c
ipip: advertise tunnel param via rtnl
[~andy/linux] / net / ipv4 / ipip.c
index e15b45297c09f0043bda21ad366ce36d5a6e5824..720855e41100476945afda37c59c622572267dd8 100644 (file)
@@ -138,6 +138,7 @@ struct ipip_net {
 static int ipip_tunnel_init(struct net_device *dev);
 static void ipip_tunnel_setup(struct net_device *dev);
 static void ipip_dev_free(struct net_device *dev);
+static struct rtnl_link_ops ipip_link_ops __read_mostly;
 
 /*
  * Locking : hash tables are protected by RCU and RTNL
@@ -305,6 +306,7 @@ static struct ip_tunnel *ipip_tunnel_locate(struct net *net,
                goto failed_free;
 
        strcpy(nt->parms.name, dev->name);
+       dev->rtnl_link_ops = &ipip_link_ops;
 
        dev_hold(dev);
        ipip_tunnel_link(ipn, nt);
@@ -479,6 +481,10 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
        if (skb->protocol != htons(ETH_P_IP))
                goto tx_error;
 
+       if (skb->ip_summed == CHECKSUM_PARTIAL &&
+           skb_checksum_help(skb))
+               goto tx_error;
+
        if (tos & 1)
                tos = old_iph->tos;
 
@@ -773,6 +779,11 @@ static void ipip_dev_free(struct net_device *dev)
        free_netdev(dev);
 }
 
+#define IPIP_FEATURES (NETIF_F_SG |            \
+                      NETIF_F_FRAGLIST |       \
+                      NETIF_F_HIGHDMA |        \
+                      NETIF_F_HW_CSUM)
+
 static void ipip_tunnel_setup(struct net_device *dev)
 {
        dev->netdev_ops         = &ipip_netdev_ops;
@@ -787,6 +798,9 @@ static void ipip_tunnel_setup(struct net_device *dev)
        dev->features           |= NETIF_F_NETNS_LOCAL;
        dev->features           |= NETIF_F_LLTX;
        dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+
+       dev->features           |= IPIP_FEATURES;
+       dev->hw_features        |= IPIP_FEATURES;
 }
 
 static int ipip_tunnel_init(struct net_device *dev)
@@ -829,6 +843,47 @@ static int __net_init ipip_fb_tunnel_init(struct net_device *dev)
        return 0;
 }
 
+static size_t ipip_get_size(const struct net_device *dev)
+{
+       return
+               /* IFLA_IPTUN_LINK */
+               nla_total_size(4) +
+               /* IFLA_IPTUN_LOCAL */
+               nla_total_size(4) +
+               /* IFLA_IPTUN_REMOTE */
+               nla_total_size(4) +
+               /* IFLA_IPTUN_TTL */
+               nla_total_size(1) +
+               /* IFLA_IPTUN_TOS */
+               nla_total_size(1) +
+               0;
+}
+
+static int ipip_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+       struct ip_tunnel *tunnel = netdev_priv(dev);
+       struct ip_tunnel_parm *parm = &tunnel->parms;
+
+       if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
+           nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
+           nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
+           nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
+           nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos))
+               goto nla_put_failure;
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+static struct rtnl_link_ops ipip_link_ops __read_mostly = {
+       .kind           = "ipip",
+       .maxtype        = IFLA_IPTUN_MAX,
+       .priv_size      = sizeof(struct ip_tunnel),
+       .get_size       = ipip_get_size,
+       .fill_info      = ipip_fill_info,
+};
+
 static struct xfrm_tunnel ipip_handler __read_mostly = {
        .handler        =       ipip_rcv,
        .err_handler    =       ipip_err,
@@ -925,14 +980,26 @@ static int __init ipip_init(void)
                return err;
        err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
        if (err < 0) {
-               unregister_pernet_device(&ipip_net_ops);
                pr_info("%s: can't register tunnel\n", __func__);
+               goto xfrm_tunnel_failed;
        }
+       err = rtnl_link_register(&ipip_link_ops);
+       if (err < 0)
+               goto rtnl_link_failed;
+
+out:
        return err;
+
+rtnl_link_failed:
+       xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
+xfrm_tunnel_failed:
+       unregister_pernet_device(&ipip_net_ops);
+       goto out;
 }
 
 static void __exit ipip_fini(void)
 {
+       rtnl_link_unregister(&ipip_link_ops);
        if (xfrm4_tunnel_deregister(&ipip_handler, AF_INET))
                pr_info("%s: can't deregister tunnel\n", __func__);