1 /* xfrm4_tunnel.c: Generic IP tunnel transformer.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
6 #include <linux/skbuff.h>
10 #include <net/inet_ecn.h>
12 int xfrm4_tunnel_check_size(struct sk_buff *skb)
15 struct dst_entry *dst;
16 struct iphdr *iph = skb->nh.iph;
18 if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE)
21 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
23 if (!(iph->frag_off & htons(IP_DF)))
27 mtu = dst_pmtu(dst) - dst->header_len - dst->trailer_len;
29 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
36 static int ipip_output(struct sk_buff **pskb)
38 struct sk_buff *skb = *pskb;
42 iph->tot_len = htons(skb->len);
48 static int ipip_xfrm_rcv(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
53 static struct xfrm_tunnel *ipip_handler;
54 static DECLARE_MUTEX(xfrm4_tunnel_sem);
56 int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
60 down(&xfrm4_tunnel_sem);
62 if (ipip_handler != NULL)
65 ipip_handler = handler;
66 up(&xfrm4_tunnel_sem);
71 int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
75 down(&xfrm4_tunnel_sem);
77 if (ipip_handler != handler)
81 up(&xfrm4_tunnel_sem);
88 static int ipip_rcv(struct sk_buff *skb)
90 struct xfrm_tunnel *handler = ipip_handler;
92 /* Tunnel devices take precedence. */
93 if (handler && handler->handler(skb) == 0)
96 return xfrm4_rcv_encap(skb, 0);
99 static void ipip_err(struct sk_buff *skb, u32 info)
101 struct xfrm_tunnel *handler = ipip_handler;
105 handler->err_handler(skb, &arg);
108 static int ipip_init_state(struct xfrm_state *x, void *args)
112 x->props.header_len = sizeof(struct iphdr);
117 static void ipip_destroy(struct xfrm_state *x)
121 static struct xfrm_type ipip_type = {
122 .description = "IPIP",
123 .owner = THIS_MODULE,
124 .proto = IPPROTO_IPIP,
125 .init_state = ipip_init_state,
126 .destructor = ipip_destroy,
127 .input = ipip_xfrm_rcv,
128 .output = ipip_output
131 static struct net_protocol ipip_protocol = {
133 .err_handler = ipip_err,
137 static int __init ipip_init(void)
139 if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
140 printk(KERN_INFO "ipip init: can't add xfrm type\n");
143 if (inet_add_protocol(&ipip_protocol, IPPROTO_IPIP) < 0) {
144 printk(KERN_INFO "ipip init: can't add protocol\n");
145 xfrm_unregister_type(&ipip_type, AF_INET);
151 static void __exit ipip_fini(void)
153 if (inet_del_protocol(&ipip_protocol, IPPROTO_IPIP) < 0)
154 printk(KERN_INFO "ipip close: can't remove protocol\n");
155 if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
156 printk(KERN_INFO "ipip close: can't remove xfrm type\n");
159 module_init(ipip_init);
160 module_exit(ipip_fini);
161 MODULE_LICENSE("GPL");