aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/ipv6/Kconfig4
-rw-r--r--net/ipv6/addrconf.c25
-rw-r--r--net/ipv6/anycast.c25
-rw-r--r--net/ipv6/ndisc.c42
-rw-r--r--net/ipv6/route.c2
-rw-r--r--net/ipv6/sit.c257
6 files changed, 284 insertions, 71 deletions
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index 82f987b4ef84..6cd2f4cdcb28 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -168,6 +168,7 @@ config IPV6_SIT
168 tristate "IPv6: IPv6-in-IPv4 tunnel (SIT driver)" 168 tristate "IPv6: IPv6-in-IPv4 tunnel (SIT driver)"
169 depends on IPV6 169 depends on IPV6
170 select INET_TUNNEL 170 select INET_TUNNEL
171 select IPV6_NDISC_NODETYPE
171 default y 172 default y
172 ---help--- 173 ---help---
173 Tunneling means encapsulating data of one protocol type within 174 Tunneling means encapsulating data of one protocol type within
@@ -178,6 +179,9 @@ config IPV6_SIT
178 179
179 Saying M here will produce a module called sit.ko. If unsure, say Y. 180 Saying M here will produce a module called sit.ko. If unsure, say Y.
180 181
182config IPV6_NDISC_NODETYPE
183 bool
184
181config IPV6_TUNNEL 185config IPV6_TUNNEL
182 tristate "IPv6: IP-in-IPv6 tunnel (RFC2473)" 186 tristate "IPv6: IP-in-IPv6 tunnel (RFC2473)"
183 select INET6_TUNNEL 187 select INET6_TUNNEL
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index dbc51af69017..924158393d04 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1265,6 +1265,31 @@ int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
1265 return ifp != NULL; 1265 return ifp != NULL;
1266} 1266}
1267 1267
1268int ipv6_chk_prefix(struct in6_addr *addr, struct net_device *dev)
1269{
1270 struct inet6_dev *idev;
1271 struct inet6_ifaddr *ifa;
1272 int onlink;
1273
1274 onlink = 0;
1275 rcu_read_lock();
1276 idev = __in6_dev_get(dev);
1277 if (idev) {
1278 read_lock_bh(&idev->lock);
1279 for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
1280 onlink = ipv6_prefix_equal(addr, &ifa->addr,
1281 ifa->prefix_len);
1282 if (onlink)
1283 break;
1284 }
1285 read_unlock_bh(&idev->lock);
1286 }
1287 rcu_read_unlock();
1288 return onlink;
1289}
1290
1291EXPORT_SYMBOL(ipv6_chk_prefix);
1292
1268struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr, 1293struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
1269 struct net_device *dev, int strict) 1294 struct net_device *dev, int strict)
1270{ 1295{
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 463bd95d6b13..36e817492095 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -48,29 +48,6 @@ static int ipv6_dev_ac_dec(struct net_device *dev, struct in6_addr *addr);
48/* Big ac list lock for all the sockets */ 48/* Big ac list lock for all the sockets */
49static DEFINE_RWLOCK(ipv6_sk_ac_lock); 49static DEFINE_RWLOCK(ipv6_sk_ac_lock);
50 50
51static int
52ip6_onlink(struct in6_addr *addr, struct net_device *dev)
53{
54 struct inet6_dev *idev;
55 struct inet6_ifaddr *ifa;
56 int onlink;
57
58 onlink = 0;
59 rcu_read_lock();
60 idev = __in6_dev_get(dev);
61 if (idev) {
62 read_lock_bh(&idev->lock);
63 for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
64 onlink = ipv6_prefix_equal(addr, &ifa->addr,
65 ifa->prefix_len);
66 if (onlink)
67 break;
68 }
69 read_unlock_bh(&idev->lock);
70 }
71 rcu_read_unlock();
72 return onlink;
73}
74 51
75/* 52/*
76 * socket join an anycast group 53 * socket join an anycast group
@@ -142,7 +119,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
142 * This obviates the need for propagating anycast routes while 119 * This obviates the need for propagating anycast routes while
143 * still allowing some non-router anycast participation. 120 * still allowing some non-router anycast participation.
144 */ 121 */
145 if (!ip6_onlink(addr, dev)) { 122 if (!ipv6_chk_prefix(addr, dev)) {
146 if (ishost) 123 if (ishost)
147 err = -EADDRNOTAVAIL; 124 err = -EADDRNOTAVAIL;
148 if (err) 125 if (err)
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 06d80c6dc5ce..b3295d82fece 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1093,6 +1093,14 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1093 return; 1093 return;
1094 } 1094 }
1095 1095
1096#ifdef CONFIG_IPV6_NDISC_NODETYPE
1097 if (skb->ndisc_nodetype == NDISC_NODETYPE_HOST) {
1098 ND_PRINTK2(KERN_WARNING
1099 "ICMPv6 RA: from host or unauthorized router\n");
1100 return;
1101 }
1102#endif
1103
1096 /* 1104 /*
1097 * set the RA_RECV flag in the interface 1105 * set the RA_RECV flag in the interface
1098 */ 1106 */
@@ -1116,6 +1124,12 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1116 return; 1124 return;
1117 } 1125 }
1118 1126
1127#ifdef CONFIG_IPV6_NDISC_NODETYPE
1128 /* skip link-specific parameters from interior routers */
1129 if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT)
1130 goto skip_linkparms;
1131#endif
1132
1119 if (in6_dev->if_flags & IF_RS_SENT) { 1133 if (in6_dev->if_flags & IF_RS_SENT) {
1120 /* 1134 /*
1121 * flag that an RA was received after an RS was sent 1135 * flag that an RA was received after an RS was sent
@@ -1230,6 +1244,10 @@ skip_defrtr:
1230 } 1244 }
1231 } 1245 }
1232 1246
1247#ifdef CONFIG_IPV6_NDISC_NODETYPE
1248skip_linkparms:
1249#endif
1250
1233 /* 1251 /*
1234 * Process options. 1252 * Process options.
1235 */ 1253 */
@@ -1261,7 +1279,13 @@ skip_defrtr:
1261 for (p = ndopts.nd_opts_ri; 1279 for (p = ndopts.nd_opts_ri;
1262 p; 1280 p;
1263 p = ndisc_next_option(p, ndopts.nd_opts_ri_end)) { 1281 p = ndisc_next_option(p, ndopts.nd_opts_ri_end)) {
1264 if (((struct route_info *)p)->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen) 1282 struct route_info *ri = (struct route_info *)p;
1283#ifdef CONFIG_IPV6_NDISC_NODETYPE
1284 if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT &&
1285 ri->prefix_len == 0)
1286 continue;
1287#endif
1288 if (ri->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen)
1265 continue; 1289 continue;
1266 rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3, 1290 rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3,
1267 &ipv6_hdr(skb)->saddr); 1291 &ipv6_hdr(skb)->saddr);
@@ -1269,6 +1293,12 @@ skip_defrtr:
1269 } 1293 }
1270#endif 1294#endif
1271 1295
1296#ifdef CONFIG_IPV6_NDISC_NODETYPE
1297 /* skip link-specific ndopts from interior routers */
1298 if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT)
1299 goto out;
1300#endif
1301
1272 if (in6_dev->cnf.accept_ra_pinfo && ndopts.nd_opts_pi) { 1302 if (in6_dev->cnf.accept_ra_pinfo && ndopts.nd_opts_pi) {
1273 struct nd_opt_hdr *p; 1303 struct nd_opt_hdr *p;
1274 for (p = ndopts.nd_opts_pi; 1304 for (p = ndopts.nd_opts_pi;
@@ -1332,6 +1362,16 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
1332 int optlen; 1362 int optlen;
1333 u8 *lladdr = NULL; 1363 u8 *lladdr = NULL;
1334 1364
1365#ifdef CONFIG_IPV6_NDISC_NODETYPE
1366 switch (skb->ndisc_nodetype) {
1367 case NDISC_NODETYPE_HOST:
1368 case NDISC_NODETYPE_NODEFAULT:
1369 ND_PRINTK2(KERN_WARNING
1370 "ICMPv6 Redirect: from host or unauthorized router\n");
1371 return;
1372 }
1373#endif
1374
1335 if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) { 1375 if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
1336 ND_PRINTK2(KERN_WARNING 1376 ND_PRINTK2(KERN_WARNING
1337 "ICMPv6 Redirect: source address is not link-local.\n"); 1377 "ICMPv6 Redirect: source address is not link-local.\n");
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 3c314d5f46c6..269b76093288 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1700,8 +1700,6 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d
1700 return rt; 1700 return rt;
1701} 1701}
1702 1702
1703EXPORT_SYMBOL(rt6_get_dflt_router);
1704
1705struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, 1703struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
1706 struct net_device *dev, 1704 struct net_device *dev,
1707 unsigned int pref) 1705 unsigned int pref)
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 1b8196c8d145..cc16fe07bbff 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -16,7 +16,7 @@
16 * Changes: 16 * Changes:
17 * Roger Venning <r.venning@telstra.com>: 6to4 support 17 * Roger Venning <r.venning@telstra.com>: 6to4 support
18 * Nate Thompson <nate@thebog.net>: 6to4 support 18 * Nate Thompson <nate@thebog.net>: 6to4 support
19 * Fred L. Templin <fltemplin@acm.org>: isatap support 19 * Fred Templin <fred.l.templin@boeing.com>: isatap support
20 */ 20 */
21 21
22#include <linux/module.h> 22#include <linux/module.h>
@@ -197,6 +197,179 @@ failed:
197 return NULL; 197 return NULL;
198} 198}
199 199
200static struct ip_tunnel_prl_entry *
201__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr)
202{
203 struct ip_tunnel_prl_entry *p = (struct ip_tunnel_prl_entry *)NULL;
204
205 for (p = t->prl; p; p = p->next)
206 if (p->addr == addr)
207 break;
208 return p;
209
210}
211
212static int ipip6_tunnel_get_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
213{
214 struct ip_tunnel_prl *kp;
215 struct ip_tunnel_prl_entry *prl;
216 unsigned int cmax, c = 0, ca, len;
217 int ret = 0;
218
219 cmax = a->datalen / sizeof(*a);
220 if (cmax > 1 && a->addr != htonl(INADDR_ANY))
221 cmax = 1;
222
223 /* For simple GET or for root users,
224 * we try harder to allocate.
225 */
226 kp = (cmax <= 1 || capable(CAP_NET_ADMIN)) ?
227 kcalloc(cmax, sizeof(*kp), GFP_KERNEL) :
228 NULL;
229
230 read_lock(&ipip6_lock);
231
232 ca = t->prl_count < cmax ? t->prl_count : cmax;
233
234 if (!kp) {
235 /* We don't try hard to allocate much memory for
236 * non-root users.
237 * For root users, retry allocating enough memory for
238 * the answer.
239 */
240 kp = kcalloc(ca, sizeof(*kp), GFP_ATOMIC);
241 if (!kp) {
242 ret = -ENOMEM;
243 goto out;
244 }
245 }
246
247 c = 0;
248 for (prl = t->prl; prl; prl = prl->next) {
249 if (c > cmax)
250 break;
251 if (a->addr != htonl(INADDR_ANY) && prl->addr != a->addr)
252 continue;
253 kp[c].addr = prl->addr;
254 kp[c].flags = prl->flags;
255 c++;
256 if (a->addr != htonl(INADDR_ANY))
257 break;
258 }
259out:
260 read_unlock(&ipip6_lock);
261
262 len = sizeof(*kp) * c;
263 ret = len ? copy_to_user(a->data, kp, len) : 0;
264
265 kfree(kp);
266 if (ret)
267 return -EFAULT;
268
269 a->datalen = len;
270 return 0;
271}
272
273static int
274ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
275{
276 struct ip_tunnel_prl_entry *p;
277 int err = 0;
278
279 if (a->addr == htonl(INADDR_ANY))
280 return -EINVAL;
281
282 write_lock(&ipip6_lock);
283
284 for (p = t->prl; p; p = p->next) {
285 if (p->addr == a->addr) {
286 if (chg)
287 goto update;
288 err = -EEXIST;
289 goto out;
290 }
291 }
292
293 if (chg) {
294 err = -ENXIO;
295 goto out;
296 }
297
298 p = kzalloc(sizeof(struct ip_tunnel_prl_entry), GFP_KERNEL);
299 if (!p) {
300 err = -ENOBUFS;
301 goto out;
302 }
303
304 p->next = t->prl;
305 t->prl = p;
306 t->prl_count++;
307update:
308 p->addr = a->addr;
309 p->flags = a->flags;
310out:
311 write_unlock(&ipip6_lock);
312 return err;
313}
314
315static int
316ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
317{
318 struct ip_tunnel_prl_entry *x, **p;
319 int err = 0;
320
321 write_lock(&ipip6_lock);
322
323 if (a && a->addr != htonl(INADDR_ANY)) {
324 for (p = &t->prl; *p; p = &(*p)->next) {
325 if ((*p)->addr == a->addr) {
326 x = *p;
327 *p = x->next;
328 kfree(x);
329 t->prl_count--;
330 goto out;
331 }
332 }
333 err = -ENXIO;
334 } else {
335 while (t->prl) {
336 x = t->prl;
337 t->prl = t->prl->next;
338 kfree(x);
339 t->prl_count--;
340 }
341 }
342out:
343 write_unlock(&ipip6_lock);
344 return 0;
345}
346
347static int
348isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t)
349{
350 struct ip_tunnel_prl_entry *p;
351 int ok = 1;
352
353 read_lock(&ipip6_lock);
354 p = __ipip6_tunnel_locate_prl(t, iph->saddr);
355 if (p) {
356 if (p->flags & PRL_DEFAULT)
357 skb->ndisc_nodetype = NDISC_NODETYPE_DEFAULT;
358 else
359 skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT;
360 } else {
361 struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr;
362 if (ipv6_addr_is_isatap(addr6) &&
363 (addr6->s6_addr32[3] == iph->saddr) &&
364 ipv6_chk_prefix(addr6, t->dev))
365 skb->ndisc_nodetype = NDISC_NODETYPE_HOST;
366 else
367 ok = 0;
368 }
369 read_unlock(&ipip6_lock);
370 return ok;
371}
372
200static void ipip6_tunnel_uninit(struct net_device *dev) 373static void ipip6_tunnel_uninit(struct net_device *dev)
201{ 374{
202 if (dev == ipip6_fb_tunnel_dev) { 375 if (dev == ipip6_fb_tunnel_dev) {
@@ -206,6 +379,7 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
206 dev_put(dev); 379 dev_put(dev);
207 } else { 380 } else {
208 ipip6_tunnel_unlink(netdev_priv(dev)); 381 ipip6_tunnel_unlink(netdev_priv(dev));
382 ipip6_tunnel_del_prl(netdev_priv(dev), 0);
209 dev_put(dev); 383 dev_put(dev);
210 } 384 }
211} 385}
@@ -365,48 +539,6 @@ static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb)
365 IP6_ECN_set_ce(ipv6_hdr(skb)); 539 IP6_ECN_set_ce(ipv6_hdr(skb));
366} 540}
367 541
368/* ISATAP (RFC4214) - check source address */
369static int
370isatap_srcok(struct sk_buff *skb, struct iphdr *iph, struct net_device *dev)
371{
372 struct neighbour *neigh;
373 struct dst_entry *dst;
374 struct rt6_info *rt;
375 struct flowi fl;
376 struct in6_addr *addr6;
377 struct in6_addr rtr;
378 struct ipv6hdr *iph6;
379 int ok = 0;
380
381 /* from onlink default router */
382 ipv6_addr_set(&rtr, htonl(0xFE800000), 0, 0, 0);
383 ipv6_isatap_eui64(rtr.s6_addr + 8, iph->saddr);
384 if ((rt = rt6_get_dflt_router(&rtr, dev))) {
385 dst_release(&rt->u.dst);
386 return 1;
387 }
388
389 iph6 = ipv6_hdr(skb);
390 memset(&fl, 0, sizeof(fl));
391 fl.proto = iph6->nexthdr;
392 ipv6_addr_copy(&fl.fl6_dst, &iph6->saddr);
393 fl.oif = dev->ifindex;
394 security_skb_classify_flow(skb, &fl);
395
396 dst = ip6_route_output(&init_net, NULL, &fl);
397 if (!dst->error && (dst->dev == dev) && (neigh = dst->neighbour)) {
398
399 addr6 = (struct in6_addr*)&neigh->primary_key;
400
401 /* from correct previous hop */
402 if (ipv6_addr_is_isatap(addr6) &&
403 (addr6->s6_addr32[3] == iph->saddr))
404 ok = 1;
405 }
406 dst_release(dst);
407 return ok;
408}
409
410static int ipip6_rcv(struct sk_buff *skb) 542static int ipip6_rcv(struct sk_buff *skb)
411{ 543{
412 struct iphdr *iph; 544 struct iphdr *iph;
@@ -427,7 +559,7 @@ static int ipip6_rcv(struct sk_buff *skb)
427 skb->pkt_type = PACKET_HOST; 559 skb->pkt_type = PACKET_HOST;
428 560
429 if ((tunnel->dev->priv_flags & IFF_ISATAP) && 561 if ((tunnel->dev->priv_flags & IFF_ISATAP) &&
430 !isatap_srcok(skb, iph, tunnel->dev)) { 562 !isatap_chksrc(skb, iph, tunnel)) {
431 tunnel->stat.rx_errors++; 563 tunnel->stat.rx_errors++;
432 read_unlock(&ipip6_lock); 564 read_unlock(&ipip6_lock);
433 kfree_skb(skb); 565 kfree_skb(skb);
@@ -707,6 +839,7 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
707{ 839{
708 int err = 0; 840 int err = 0;
709 struct ip_tunnel_parm p; 841 struct ip_tunnel_parm p;
842 struct ip_tunnel_prl prl;
710 struct ip_tunnel *t; 843 struct ip_tunnel *t;
711 844
712 switch (cmd) { 845 switch (cmd) {
@@ -806,6 +939,42 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
806 err = 0; 939 err = 0;
807 break; 940 break;
808 941
942 case SIOCGETPRL:
943 case SIOCADDPRL:
944 case SIOCDELPRL:
945 case SIOCCHGPRL:
946 err = -EPERM;
947 if (cmd != SIOCGETPRL && !capable(CAP_NET_ADMIN))
948 goto done;
949 err = -EINVAL;
950 if (dev == ipip6_fb_tunnel_dev)
951 goto done;
952 err = -EFAULT;
953 if (copy_from_user(&prl, ifr->ifr_ifru.ifru_data, sizeof(prl)))
954 goto done;
955 err = -ENOENT;
956 if (!(t = netdev_priv(dev)))
957 goto done;
958
959 switch (cmd) {
960 case SIOCGETPRL:
961 err = ipip6_tunnel_get_prl(t, &prl);
962 if (!err && copy_to_user(ifr->ifr_ifru.ifru_data,
963 &prl, sizeof(prl)))
964 err = -EFAULT;
965 break;
966 case SIOCDELPRL:
967 err = ipip6_tunnel_del_prl(t, &prl);
968 break;
969 case SIOCADDPRL:
970 case SIOCCHGPRL:
971 err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL);
972 break;
973 }
974 if (cmd != SIOCGETPRL)
975 netdev_state_change(dev);
976 break;
977
809 default: 978 default:
810 err = -EINVAL; 979 err = -EINVAL;
811 } 980 }