2 * Linux NET3: IP/IP protocol decoder modified to support
3 * virtual tunnel interface
6 * Saurabh Mohan (saurabh.mohan@vyatta.com) 05/07/2012
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
16 This version of net/ipv4/ip_vti.c is cloned of net/ipv4/ipip.c
18 For comments look at net/ipv4/ip_gre.c --ANK
22 #include <linux/capability.h>
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/uaccess.h>
27 #include <linux/skbuff.h>
28 #include <linux/netdevice.h>
30 #include <linux/tcp.h>
31 #include <linux/udp.h>
32 #include <linux/if_arp.h>
33 #include <linux/mroute.h>
34 #include <linux/init.h>
35 #include <linux/netfilter_ipv4.h>
36 #include <linux/if_ether.h>
42 #include <net/inet_ecn.h>
44 #include <net/net_namespace.h>
45 #include <net/netns/generic.h>
48 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
50 static struct rtnl_link_ops vti_link_ops __read_mostly
;
52 static int vti_net_id __read_mostly
;
54 struct ip_tunnel __rcu
*tunnels_r_l
[HASH_SIZE
];
55 struct ip_tunnel __rcu
*tunnels_r
[HASH_SIZE
];
56 struct ip_tunnel __rcu
*tunnels_l
[HASH_SIZE
];
57 struct ip_tunnel __rcu
*tunnels_wc
[1];
58 struct ip_tunnel __rcu
**tunnels
[4];
60 struct net_device
*fb_tunnel_dev
;
63 static int vti_fb_tunnel_init(struct net_device
*dev
);
64 static int vti_tunnel_init(struct net_device
*dev
);
65 static void vti_tunnel_setup(struct net_device
*dev
);
66 static void vti_dev_free(struct net_device
*dev
);
67 static int vti_tunnel_bind_dev(struct net_device
*dev
);
69 /* Locking : hash tables are protected by RCU and RTNL */
71 #define for_each_ip_tunnel_rcu(start) \
72 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
74 /* often modified stats are per cpu, other are shared (netdev->stats) */
80 struct u64_stats_sync syncp
;
83 #define VTI_XMIT(stats1, stats2) do { \
85 int pkt_len = skb->len; \
86 err = dst_output(skb); \
87 if (net_xmit_eval(err) == 0) { \
88 u64_stats_update_begin(&(stats1)->syncp); \
89 (stats1)->tx_bytes += pkt_len; \
90 (stats1)->tx_packets++; \
91 u64_stats_update_end(&(stats1)->syncp); \
93 (stats2)->tx_errors++; \
94 (stats2)->tx_aborted_errors++; \
99 static struct rtnl_link_stats64
*vti_get_stats64(struct net_device
*dev
,
100 struct rtnl_link_stats64
*tot
)
104 for_each_possible_cpu(i
) {
105 const struct pcpu_tstats
*tstats
= per_cpu_ptr(dev
->tstats
, i
);
106 u64 rx_packets
, rx_bytes
, tx_packets
, tx_bytes
;
110 start
= u64_stats_fetch_begin_bh(&tstats
->syncp
);
111 rx_packets
= tstats
->rx_packets
;
112 tx_packets
= tstats
->tx_packets
;
113 rx_bytes
= tstats
->rx_bytes
;
114 tx_bytes
= tstats
->tx_bytes
;
115 } while (u64_stats_fetch_retry_bh(&tstats
->syncp
, start
));
117 tot
->rx_packets
+= rx_packets
;
118 tot
->tx_packets
+= tx_packets
;
119 tot
->rx_bytes
+= rx_bytes
;
120 tot
->tx_bytes
+= tx_bytes
;
123 tot
->multicast
= dev
->stats
.multicast
;
124 tot
->rx_crc_errors
= dev
->stats
.rx_crc_errors
;
125 tot
->rx_fifo_errors
= dev
->stats
.rx_fifo_errors
;
126 tot
->rx_length_errors
= dev
->stats
.rx_length_errors
;
127 tot
->rx_errors
= dev
->stats
.rx_errors
;
128 tot
->tx_fifo_errors
= dev
->stats
.tx_fifo_errors
;
129 tot
->tx_carrier_errors
= dev
->stats
.tx_carrier_errors
;
130 tot
->tx_dropped
= dev
->stats
.tx_dropped
;
131 tot
->tx_aborted_errors
= dev
->stats
.tx_aborted_errors
;
132 tot
->tx_errors
= dev
->stats
.tx_errors
;
137 static struct ip_tunnel
*vti_tunnel_lookup(struct net
*net
,
138 __be32 remote
, __be32 local
)
140 unsigned h0
= HASH(remote
);
141 unsigned h1
= HASH(local
);
143 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
145 for_each_ip_tunnel_rcu(ipn
->tunnels_r_l
[h0
^ h1
])
146 if (local
== t
->parms
.iph
.saddr
&&
147 remote
== t
->parms
.iph
.daddr
&& (t
->dev
->flags
&IFF_UP
))
149 for_each_ip_tunnel_rcu(ipn
->tunnels_r
[h0
])
150 if (remote
== t
->parms
.iph
.daddr
&& (t
->dev
->flags
&IFF_UP
))
153 for_each_ip_tunnel_rcu(ipn
->tunnels_l
[h1
])
154 if (local
== t
->parms
.iph
.saddr
&& (t
->dev
->flags
&IFF_UP
))
157 for_each_ip_tunnel_rcu(ipn
->tunnels_wc
[0])
158 if (t
&& (t
->dev
->flags
&IFF_UP
))
163 static struct ip_tunnel __rcu
**__vti_bucket(struct vti_net
*ipn
,
164 struct ip_tunnel_parm
*parms
)
166 __be32 remote
= parms
->iph
.daddr
;
167 __be32 local
= parms
->iph
.saddr
;
179 return &ipn
->tunnels
[prio
][h
];
182 static inline struct ip_tunnel __rcu
**vti_bucket(struct vti_net
*ipn
,
185 return __vti_bucket(ipn
, &t
->parms
);
188 static void vti_tunnel_unlink(struct vti_net
*ipn
, struct ip_tunnel
*t
)
190 struct ip_tunnel __rcu
**tp
;
191 struct ip_tunnel
*iter
;
193 for (tp
= vti_bucket(ipn
, t
);
194 (iter
= rtnl_dereference(*tp
)) != NULL
;
197 rcu_assign_pointer(*tp
, t
->next
);
203 static void vti_tunnel_link(struct vti_net
*ipn
, struct ip_tunnel
*t
)
205 struct ip_tunnel __rcu
**tp
= vti_bucket(ipn
, t
);
207 rcu_assign_pointer(t
->next
, rtnl_dereference(*tp
));
208 rcu_assign_pointer(*tp
, t
);
211 static struct ip_tunnel
*vti_tunnel_locate(struct net
*net
,
212 struct ip_tunnel_parm
*parms
,
215 __be32 remote
= parms
->iph
.daddr
;
216 __be32 local
= parms
->iph
.saddr
;
217 struct ip_tunnel
*t
, *nt
;
218 struct ip_tunnel __rcu
**tp
;
219 struct net_device
*dev
;
221 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
223 for (tp
= __vti_bucket(ipn
, parms
);
224 (t
= rtnl_dereference(*tp
)) != NULL
;
226 if (local
== t
->parms
.iph
.saddr
&& remote
== t
->parms
.iph
.daddr
)
233 strlcpy(name
, parms
->name
, IFNAMSIZ
);
235 strcpy(name
, "vti%d");
237 dev
= alloc_netdev(sizeof(*t
), name
, vti_tunnel_setup
);
241 dev_net_set(dev
, net
);
243 nt
= netdev_priv(dev
);
245 dev
->rtnl_link_ops
= &vti_link_ops
;
247 vti_tunnel_bind_dev(dev
);
249 if (register_netdevice(dev
) < 0)
253 vti_tunnel_link(ipn
, nt
);
261 static void vti_tunnel_uninit(struct net_device
*dev
)
263 struct net
*net
= dev_net(dev
);
264 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
266 vti_tunnel_unlink(ipn
, netdev_priv(dev
));
270 static int vti_err(struct sk_buff
*skb
, u32 info
)
273 /* All the routers (except for Linux) return only
274 * 8 bytes of packet payload. It means, that precise relaying of
275 * ICMP in the real Internet is absolutely infeasible.
277 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
278 const int type
= icmp_hdr(skb
)->type
;
279 const int code
= icmp_hdr(skb
)->code
;
285 case ICMP_PARAMETERPROB
:
288 case ICMP_DEST_UNREACH
:
291 case ICMP_PORT_UNREACH
:
292 /* Impossible event. */
295 /* All others are translated to HOST_UNREACH. */
299 case ICMP_TIME_EXCEEDED
:
300 if (code
!= ICMP_EXC_TTL
)
308 t
= vti_tunnel_lookup(dev_net(skb
->dev
), iph
->daddr
, iph
->saddr
);
312 if (type
== ICMP_DEST_UNREACH
&& code
== ICMP_FRAG_NEEDED
) {
313 ipv4_update_pmtu(skb
, dev_net(skb
->dev
), info
,
314 t
->parms
.link
, 0, IPPROTO_IPIP
, 0);
320 if (t
->parms
.iph
.ttl
== 0 && type
== ICMP_TIME_EXCEEDED
)
323 if (time_before(jiffies
, t
->err_time
+ IPTUNNEL_ERR_TIMEO
))
327 t
->err_time
= jiffies
;
333 /* We dont digest the packet therefore let the packet pass */
334 static int vti_rcv(struct sk_buff
*skb
)
336 struct ip_tunnel
*tunnel
;
337 const struct iphdr
*iph
= ip_hdr(skb
);
340 tunnel
= vti_tunnel_lookup(dev_net(skb
->dev
), iph
->saddr
, iph
->daddr
);
341 if (tunnel
!= NULL
) {
342 struct pcpu_tstats
*tstats
;
344 tstats
= this_cpu_ptr(tunnel
->dev
->tstats
);
345 u64_stats_update_begin(&tstats
->syncp
);
346 tstats
->rx_packets
++;
347 tstats
->rx_bytes
+= skb
->len
;
348 u64_stats_update_end(&tstats
->syncp
);
350 skb
->dev
= tunnel
->dev
;
359 /* This function assumes it is being called from dev_queue_xmit()
360 * and that skb is filled properly by that function.
363 static netdev_tx_t
vti_tunnel_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
365 struct ip_tunnel
*tunnel
= netdev_priv(dev
);
366 struct pcpu_tstats
*tstats
;
367 struct iphdr
*tiph
= &tunnel
->parms
.iph
;
369 struct rtable
*rt
; /* Route to the other host */
370 struct net_device
*tdev
; /* Device to other host */
371 struct iphdr
*old_iph
= ip_hdr(skb
);
372 __be32 dst
= tiph
->daddr
;
375 if (skb
->protocol
!= htons(ETH_P_IP
))
380 memset(&fl4
, 0, sizeof(fl4
));
381 flowi4_init_output(&fl4
, tunnel
->parms
.link
,
382 htonl(tunnel
->parms
.i_key
), RT_TOS(tos
),
385 dst
, tiph
->saddr
, 0, 0);
386 rt
= ip_route_output_key(dev_net(dev
), &fl4
);
388 dev
->stats
.tx_carrier_errors
++;
391 /* if there is no transform then this tunnel is not functional.
392 * Or if the xfrm is not mode tunnel.
395 rt
->dst
.xfrm
->props
.mode
!= XFRM_MODE_TUNNEL
) {
396 dev
->stats
.tx_carrier_errors
++;
403 dev
->stats
.collisions
++;
407 if (tunnel
->err_count
> 0) {
408 if (time_before(jiffies
,
409 tunnel
->err_time
+ IPTUNNEL_ERR_TIMEO
)) {
411 dst_link_failure(skb
);
413 tunnel
->err_count
= 0;
416 IPCB(skb
)->flags
&= ~(IPSKB_XFRM_TUNNEL_SIZE
| IPSKB_XFRM_TRANSFORMED
|
419 skb_dst_set(skb
, &rt
->dst
);
421 skb
->dev
= skb_dst(skb
)->dev
;
423 tstats
= this_cpu_ptr(dev
->tstats
);
424 VTI_XMIT(tstats
, &dev
->stats
);
428 dst_link_failure(skb
);
430 dev
->stats
.tx_errors
++;
435 static int vti_tunnel_bind_dev(struct net_device
*dev
)
437 struct net_device
*tdev
= NULL
;
438 struct ip_tunnel
*tunnel
;
441 tunnel
= netdev_priv(dev
);
442 iph
= &tunnel
->parms
.iph
;
447 memset(&fl4
, 0, sizeof(fl4
));
448 flowi4_init_output(&fl4
, tunnel
->parms
.link
,
449 htonl(tunnel
->parms
.i_key
),
450 RT_TOS(iph
->tos
), RT_SCOPE_UNIVERSE
,
452 iph
->daddr
, iph
->saddr
, 0, 0);
453 rt
= ip_route_output_key(dev_net(dev
), &fl4
);
458 dev
->flags
|= IFF_POINTOPOINT
;
461 if (!tdev
&& tunnel
->parms
.link
)
462 tdev
= __dev_get_by_index(dev_net(dev
), tunnel
->parms
.link
);
465 dev
->hard_header_len
= tdev
->hard_header_len
+
466 sizeof(struct iphdr
);
467 dev
->mtu
= tdev
->mtu
;
469 dev
->iflink
= tunnel
->parms
.link
;
474 vti_tunnel_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
477 struct ip_tunnel_parm p
;
479 struct net
*net
= dev_net(dev
);
480 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
485 if (dev
== ipn
->fb_tunnel_dev
) {
486 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
,
491 t
= vti_tunnel_locate(net
, &p
, 0);
494 t
= netdev_priv(dev
);
495 memcpy(&p
, &t
->parms
, sizeof(p
));
496 p
.i_flags
|= GRE_KEY
| VTI_ISVTI
;
497 p
.o_flags
|= GRE_KEY
;
498 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
505 if (!capable(CAP_NET_ADMIN
))
509 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
513 if (p
.iph
.version
!= 4 || p
.iph
.protocol
!= IPPROTO_IPIP
||
517 t
= vti_tunnel_locate(net
, &p
, cmd
== SIOCADDTUNNEL
);
519 if (dev
!= ipn
->fb_tunnel_dev
&& cmd
== SIOCCHGTUNNEL
) {
526 if (((dev
->flags
&IFF_POINTOPOINT
) &&
528 (!(dev
->flags
&IFF_POINTOPOINT
) &&
533 t
= netdev_priv(dev
);
534 vti_tunnel_unlink(ipn
, t
);
536 t
->parms
.iph
.saddr
= p
.iph
.saddr
;
537 t
->parms
.iph
.daddr
= p
.iph
.daddr
;
538 t
->parms
.i_key
= p
.i_key
;
539 t
->parms
.o_key
= p
.o_key
;
540 t
->parms
.iph
.protocol
= IPPROTO_IPIP
;
541 memcpy(dev
->dev_addr
, &p
.iph
.saddr
, 4);
542 memcpy(dev
->broadcast
, &p
.iph
.daddr
, 4);
543 vti_tunnel_link(ipn
, t
);
544 netdev_state_change(dev
);
550 if (cmd
== SIOCCHGTUNNEL
) {
551 t
->parms
.i_key
= p
.i_key
;
552 t
->parms
.o_key
= p
.o_key
;
553 if (t
->parms
.link
!= p
.link
) {
554 t
->parms
.link
= p
.link
;
555 vti_tunnel_bind_dev(dev
);
556 netdev_state_change(dev
);
559 p
.i_flags
|= GRE_KEY
| VTI_ISVTI
;
560 p
.o_flags
|= GRE_KEY
;
561 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &t
->parms
,
565 err
= (cmd
== SIOCADDTUNNEL
? -ENOBUFS
: -ENOENT
);
570 if (!capable(CAP_NET_ADMIN
))
573 if (dev
== ipn
->fb_tunnel_dev
) {
575 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
,
580 t
= vti_tunnel_locate(net
, &p
, 0);
584 if (t
->dev
== ipn
->fb_tunnel_dev
)
588 unregister_netdevice(dev
);
600 static int vti_tunnel_change_mtu(struct net_device
*dev
, int new_mtu
)
602 if (new_mtu
< 68 || new_mtu
> 0xFFF8)
608 static const struct net_device_ops vti_netdev_ops
= {
609 .ndo_init
= vti_tunnel_init
,
610 .ndo_uninit
= vti_tunnel_uninit
,
611 .ndo_start_xmit
= vti_tunnel_xmit
,
612 .ndo_do_ioctl
= vti_tunnel_ioctl
,
613 .ndo_change_mtu
= vti_tunnel_change_mtu
,
614 .ndo_get_stats64
= vti_get_stats64
,
617 static void vti_dev_free(struct net_device
*dev
)
619 free_percpu(dev
->tstats
);
623 static void vti_tunnel_setup(struct net_device
*dev
)
625 dev
->netdev_ops
= &vti_netdev_ops
;
626 dev
->destructor
= vti_dev_free
;
628 dev
->type
= ARPHRD_TUNNEL
;
629 dev
->hard_header_len
= LL_MAX_HEADER
+ sizeof(struct iphdr
);
630 dev
->mtu
= ETH_DATA_LEN
;
631 dev
->flags
= IFF_NOARP
;
634 dev
->features
|= NETIF_F_NETNS_LOCAL
;
635 dev
->features
|= NETIF_F_LLTX
;
636 dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
639 static int vti_tunnel_init(struct net_device
*dev
)
641 struct ip_tunnel
*tunnel
= netdev_priv(dev
);
644 strcpy(tunnel
->parms
.name
, dev
->name
);
646 memcpy(dev
->dev_addr
, &tunnel
->parms
.iph
.saddr
, 4);
647 memcpy(dev
->broadcast
, &tunnel
->parms
.iph
.daddr
, 4);
649 dev
->tstats
= alloc_percpu(struct pcpu_tstats
);
656 static int __net_init
vti_fb_tunnel_init(struct net_device
*dev
)
658 struct ip_tunnel
*tunnel
= netdev_priv(dev
);
659 struct iphdr
*iph
= &tunnel
->parms
.iph
;
660 struct vti_net
*ipn
= net_generic(dev_net(dev
), vti_net_id
);
663 strcpy(tunnel
->parms
.name
, dev
->name
);
666 iph
->protocol
= IPPROTO_IPIP
;
669 dev
->tstats
= alloc_percpu(struct pcpu_tstats
);
674 rcu_assign_pointer(ipn
->tunnels_wc
[0], tunnel
);
678 static struct xfrm_tunnel vti_handler __read_mostly
= {
680 .err_handler
= vti_err
,
684 static void vti_destroy_tunnels(struct vti_net
*ipn
, struct list_head
*head
)
688 for (prio
= 1; prio
< 4; prio
++) {
690 for (h
= 0; h
< HASH_SIZE
; h
++) {
693 t
= rtnl_dereference(ipn
->tunnels
[prio
][h
]);
695 unregister_netdevice_queue(t
->dev
, head
);
696 t
= rtnl_dereference(t
->next
);
702 static int __net_init
vti_init_net(struct net
*net
)
705 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
707 ipn
->tunnels
[0] = ipn
->tunnels_wc
;
708 ipn
->tunnels
[1] = ipn
->tunnels_l
;
709 ipn
->tunnels
[2] = ipn
->tunnels_r
;
710 ipn
->tunnels
[3] = ipn
->tunnels_r_l
;
712 ipn
->fb_tunnel_dev
= alloc_netdev(sizeof(struct ip_tunnel
),
715 if (!ipn
->fb_tunnel_dev
) {
719 dev_net_set(ipn
->fb_tunnel_dev
, net
);
721 err
= vti_fb_tunnel_init(ipn
->fb_tunnel_dev
);
724 ipn
->fb_tunnel_dev
->rtnl_link_ops
= &vti_link_ops
;
726 err
= register_netdev(ipn
->fb_tunnel_dev
);
732 vti_dev_free(ipn
->fb_tunnel_dev
);
738 static void __net_exit
vti_exit_net(struct net
*net
)
740 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
744 vti_destroy_tunnels(ipn
, &list
);
745 unregister_netdevice_many(&list
);
749 static struct pernet_operations vti_net_ops
= {
750 .init
= vti_init_net
,
751 .exit
= vti_exit_net
,
753 .size
= sizeof(struct vti_net
),
756 static int vti_tunnel_validate(struct nlattr
*tb
[], struct nlattr
*data
[])
761 static void vti_netlink_parms(struct nlattr
*data
[],
762 struct ip_tunnel_parm
*parms
)
764 memset(parms
, 0, sizeof(*parms
));
766 parms
->iph
.protocol
= IPPROTO_IPIP
;
771 if (data
[IFLA_VTI_LINK
])
772 parms
->link
= nla_get_u32(data
[IFLA_VTI_LINK
]);
774 if (data
[IFLA_VTI_IKEY
])
775 parms
->i_key
= nla_get_be32(data
[IFLA_VTI_IKEY
]);
777 if (data
[IFLA_VTI_OKEY
])
778 parms
->o_key
= nla_get_be32(data
[IFLA_VTI_OKEY
]);
780 if (data
[IFLA_VTI_LOCAL
])
781 parms
->iph
.saddr
= nla_get_be32(data
[IFLA_VTI_LOCAL
]);
783 if (data
[IFLA_VTI_REMOTE
])
784 parms
->iph
.daddr
= nla_get_be32(data
[IFLA_VTI_REMOTE
]);
788 static int vti_newlink(struct net
*src_net
, struct net_device
*dev
,
789 struct nlattr
*tb
[], struct nlattr
*data
[])
791 struct ip_tunnel
*nt
;
792 struct net
*net
= dev_net(dev
);
793 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
797 nt
= netdev_priv(dev
);
798 vti_netlink_parms(data
, &nt
->parms
);
800 if (vti_tunnel_locate(net
, &nt
->parms
, 0))
803 mtu
= vti_tunnel_bind_dev(dev
);
807 err
= register_netdevice(dev
);
812 vti_tunnel_link(ipn
, nt
);
818 static int vti_changelink(struct net_device
*dev
, struct nlattr
*tb
[],
819 struct nlattr
*data
[])
821 struct ip_tunnel
*t
, *nt
;
822 struct net
*net
= dev_net(dev
);
823 struct vti_net
*ipn
= net_generic(net
, vti_net_id
);
824 struct ip_tunnel_parm p
;
827 if (dev
== ipn
->fb_tunnel_dev
)
830 nt
= netdev_priv(dev
);
831 vti_netlink_parms(data
, &p
);
833 t
= vti_tunnel_locate(net
, &p
, 0);
841 vti_tunnel_unlink(ipn
, t
);
842 t
->parms
.iph
.saddr
= p
.iph
.saddr
;
843 t
->parms
.iph
.daddr
= p
.iph
.daddr
;
844 t
->parms
.i_key
= p
.i_key
;
845 t
->parms
.o_key
= p
.o_key
;
846 if (dev
->type
!= ARPHRD_ETHER
) {
847 memcpy(dev
->dev_addr
, &p
.iph
.saddr
, 4);
848 memcpy(dev
->broadcast
, &p
.iph
.daddr
, 4);
850 vti_tunnel_link(ipn
, t
);
851 netdev_state_change(dev
);
854 if (t
->parms
.link
!= p
.link
) {
855 t
->parms
.link
= p
.link
;
856 mtu
= vti_tunnel_bind_dev(dev
);
859 netdev_state_change(dev
);
865 static size_t vti_get_size(const struct net_device
*dev
)
876 /* IFLA_VTI_REMOTE */
881 static int vti_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
883 struct ip_tunnel
*t
= netdev_priv(dev
);
884 struct ip_tunnel_parm
*p
= &t
->parms
;
886 nla_put_u32(skb
, IFLA_VTI_LINK
, p
->link
);
887 nla_put_be32(skb
, IFLA_VTI_IKEY
, p
->i_key
);
888 nla_put_be32(skb
, IFLA_VTI_OKEY
, p
->o_key
);
889 nla_put_be32(skb
, IFLA_VTI_LOCAL
, p
->iph
.saddr
);
890 nla_put_be32(skb
, IFLA_VTI_REMOTE
, p
->iph
.daddr
);
895 static const struct nla_policy vti_policy
[IFLA_VTI_MAX
+ 1] = {
896 [IFLA_VTI_LINK
] = { .type
= NLA_U32
},
897 [IFLA_VTI_IKEY
] = { .type
= NLA_U32
},
898 [IFLA_VTI_OKEY
] = { .type
= NLA_U32
},
899 [IFLA_VTI_LOCAL
] = { .len
= FIELD_SIZEOF(struct iphdr
, saddr
) },
900 [IFLA_VTI_REMOTE
] = { .len
= FIELD_SIZEOF(struct iphdr
, daddr
) },
903 static struct rtnl_link_ops vti_link_ops __read_mostly
= {
905 .maxtype
= IFLA_VTI_MAX
,
906 .policy
= vti_policy
,
907 .priv_size
= sizeof(struct ip_tunnel
),
908 .setup
= vti_tunnel_setup
,
909 .validate
= vti_tunnel_validate
,
910 .newlink
= vti_newlink
,
911 .changelink
= vti_changelink
,
912 .get_size
= vti_get_size
,
913 .fill_info
= vti_fill_info
,
916 static int __init
vti_init(void)
920 pr_info("IPv4 over IPSec tunneling driver\n");
922 err
= register_pernet_device(&vti_net_ops
);
925 err
= xfrm4_mode_tunnel_input_register(&vti_handler
);
927 unregister_pernet_device(&vti_net_ops
);
928 pr_info(KERN_INFO
"vti init: can't register tunnel\n");
931 err
= rtnl_link_register(&vti_link_ops
);
933 goto rtnl_link_failed
;
938 xfrm4_mode_tunnel_input_deregister(&vti_handler
);
939 unregister_pernet_device(&vti_net_ops
);
943 static void __exit
vti_fini(void)
945 rtnl_link_unregister(&vti_link_ops
);
946 if (xfrm4_mode_tunnel_input_deregister(&vti_handler
))
947 pr_info("vti close: can't deregister tunnel\n");
949 unregister_pernet_device(&vti_net_ops
);
952 module_init(vti_init
);
953 module_exit(vti_fini
);
954 MODULE_LICENSE("GPL");
955 MODULE_ALIAS_RTNL_LINK("vti");
956 MODULE_ALIAS_NETDEV("ip_vti0");