aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@linux-foundation.org>2007-03-08 23:44:43 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:24:11 -0400
commit132adf54639cf7dd9315e8df89c2faa59f6e46d9 (patch)
tree256e3e30e843e6144bdae68e4aad181db5819d0e /net/ipv4
parent1ac58ee37f439044eb09381f33c97ce0e7f2643b (diff)
[IPV4]: cleanup
Add whitespace around keywords. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/af_inet.c2
-rw-r--r--net/ipv4/arp.c2
-rw-r--r--net/ipv4/cipso_ipv4.c2
-rw-r--r--net/ipv4/devinet.c4
-rw-r--r--net/ipv4/fib_trie.c17
-rw-r--r--net/ipv4/ip_fragment.c26
-rw-r--r--net/ipv4/ip_output.c2
-rw-r--r--net/ipv4/ip_sockglue.c1127
-rw-r--r--net/ipv4/ipconfig.c4
-rw-r--r--net/ipv4/ipmr.c305
-rw-r--r--net/ipv4/xfrm4_mode_tunnel.c2
-rw-r--r--net/ipv4/xfrm4_policy.c2
12 files changed, 745 insertions, 750 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index df41856fc603..6e5575b0abef 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1339,7 +1339,7 @@ static int __init inet_init(void)
1339 * Initialise per-cpu ipv4 mibs 1339 * Initialise per-cpu ipv4 mibs
1340 */ 1340 */
1341 1341
1342 if(init_ipv4_mibs()) 1342 if (init_ipv4_mibs())
1343 printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ; 1343 printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
1344 1344
1345 ipv4_proc_init(); 1345 ipv4_proc_init();
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 1a3488a83f49..e6e196cd3b8c 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1178,7 +1178,7 @@ int arp_ioctl(unsigned int cmd, void __user *arg)
1178 goto out; 1178 goto out;
1179 } 1179 }
1180 1180
1181 switch(cmd) { 1181 switch (cmd) {
1182 case SIOCDARP: 1182 case SIOCDARP:
1183 err = arp_req_delete(&r, dev); 1183 err = arp_req_delete(&r, dev);
1184 break; 1184 break;
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 2ce5b693a8bd..b0182aa2c81a 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -1174,7 +1174,7 @@ static int cipso_v4_map_cat_rng_ntoh(const struct cipso_v4_doi *doi_def,
1174 u16 cat_low; 1174 u16 cat_low;
1175 u16 cat_high; 1175 u16 cat_high;
1176 1176
1177 for(net_iter = 0; net_iter < net_cat_len; net_iter += 4) { 1177 for (net_iter = 0; net_iter < net_cat_len; net_iter += 4) {
1178 cat_high = ntohs(*((__be16 *)&net_cat[net_iter])); 1178 cat_high = ntohs(*((__be16 *)&net_cat[net_iter]));
1179 if ((net_iter + 4) <= net_cat_len) 1179 if ((net_iter + 4) <= net_cat_len)
1180 cat_low = ntohs(*((__be16 *)&net_cat[net_iter + 2])); 1180 cat_low = ntohs(*((__be16 *)&net_cat[net_iter + 2]));
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 98a00d0edc76..043857bd151c 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -633,7 +633,7 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
633 dev_load(ifr.ifr_name); 633 dev_load(ifr.ifr_name);
634#endif 634#endif
635 635
636 switch(cmd) { 636 switch (cmd) {
637 case SIOCGIFADDR: /* Get interface address */ 637 case SIOCGIFADDR: /* Get interface address */
638 case SIOCGIFBRDADDR: /* Get the broadcast address */ 638 case SIOCGIFBRDADDR: /* Get the broadcast address */
639 case SIOCGIFDSTADDR: /* Get the destination address */ 639 case SIOCGIFDSTADDR: /* Get the destination address */
@@ -708,7 +708,7 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
708 if (!ifa && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS) 708 if (!ifa && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS)
709 goto done; 709 goto done;
710 710
711 switch(cmd) { 711 switch (cmd) {
712 case SIOCGIFADDR: /* Get interface address */ 712 case SIOCGIFADDR: /* Get interface address */
713 sin->sin_addr.s_addr = ifa->ifa_local; 713 sin->sin_addr.s_addr = ifa->ifa_local;
714 goto rarok; 714 goto rarok;
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 214c34732e84..c331c433acf2 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -350,11 +350,10 @@ static void __tnode_free_rcu(struct rcu_head *head)
350 350
351static inline void tnode_free(struct tnode *tn) 351static inline void tnode_free(struct tnode *tn)
352{ 352{
353 if(IS_LEAF(tn)) { 353 if (IS_LEAF(tn)) {
354 struct leaf *l = (struct leaf *) tn; 354 struct leaf *l = (struct leaf *) tn;
355 call_rcu_bh(&l->rcu, __leaf_free_rcu); 355 call_rcu_bh(&l->rcu, __leaf_free_rcu);
356 } 356 } else
357 else
358 call_rcu(&tn->rcu, __tnode_free_rcu); 357 call_rcu(&tn->rcu, __tnode_free_rcu);
359} 358}
360 359
@@ -553,7 +552,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
553 552
554 /* Keep root node larger */ 553 /* Keep root node larger */
555 554
556 if(!tn->parent) 555 if (!tn->parent)
557 inflate_threshold_use = inflate_threshold_root; 556 inflate_threshold_use = inflate_threshold_root;
558 else 557 else
559 inflate_threshold_use = inflate_threshold; 558 inflate_threshold_use = inflate_threshold;
@@ -584,7 +583,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
584 583
585 /* Keep root node larger */ 584 /* Keep root node larger */
586 585
587 if(!tn->parent) 586 if (!tn->parent)
588 halve_threshold_use = halve_threshold_root; 587 halve_threshold_use = halve_threshold_root;
589 else 588 else
590 halve_threshold_use = halve_threshold; 589 halve_threshold_use = halve_threshold;
@@ -2039,12 +2038,12 @@ static struct node *fib_trie_get_first(struct fib_trie_iter *iter,
2039{ 2038{
2040 struct node *n ; 2039 struct node *n ;
2041 2040
2042 if(!t) 2041 if (!t)
2043 return NULL; 2042 return NULL;
2044 2043
2045 n = rcu_dereference(t->trie); 2044 n = rcu_dereference(t->trie);
2046 2045
2047 if(!iter) 2046 if (!iter)
2048 return NULL; 2047 return NULL;
2049 2048
2050 if (n) { 2049 if (n) {
@@ -2084,7 +2083,7 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
2084 int i; 2083 int i;
2085 2084
2086 s->tnodes++; 2085 s->tnodes++;
2087 if(tn->bits < MAX_STAT_DEPTH) 2086 if (tn->bits < MAX_STAT_DEPTH)
2088 s->nodesizes[tn->bits]++; 2087 s->nodesizes[tn->bits]++;
2089 2088
2090 for (i = 0; i < (1<<tn->bits); i++) 2089 for (i = 0; i < (1<<tn->bits); i++)
@@ -2250,7 +2249,7 @@ static inline const char *rtn_scope(enum rt_scope_t s)
2250{ 2249{
2251 static char buf[32]; 2250 static char buf[32];
2252 2251
2253 switch(s) { 2252 switch (s) {
2254 case RT_SCOPE_UNIVERSE: return "universe"; 2253 case RT_SCOPE_UNIVERSE: return "universe";
2255 case RT_SCOPE_SITE: return "site"; 2254 case RT_SCOPE_SITE: return "site";
2256 case RT_SCOPE_LINK: return "link"; 2255 case RT_SCOPE_LINK: return "link";
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index e10be7d7752d..3dfd7581cfc6 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -184,7 +184,7 @@ static __inline__ struct ipq *frag_alloc_queue(void)
184{ 184{
185 struct ipq *qp = kmalloc(sizeof(struct ipq), GFP_ATOMIC); 185 struct ipq *qp = kmalloc(sizeof(struct ipq), GFP_ATOMIC);
186 186
187 if(!qp) 187 if (!qp)
188 return NULL; 188 return NULL;
189 atomic_add(sizeof(struct ipq), &ip_frag_mem); 189 atomic_add(sizeof(struct ipq), &ip_frag_mem);
190 return qp; 190 return qp;
@@ -321,11 +321,11 @@ static struct ipq *ip_frag_intern(struct ipq *qp_in)
321 * promoted read lock to write lock. 321 * promoted read lock to write lock.
322 */ 322 */
323 hlist_for_each_entry(qp, n, &ipq_hash[hash], list) { 323 hlist_for_each_entry(qp, n, &ipq_hash[hash], list) {
324 if(qp->id == qp_in->id && 324 if (qp->id == qp_in->id &&
325 qp->saddr == qp_in->saddr && 325 qp->saddr == qp_in->saddr &&
326 qp->daddr == qp_in->daddr && 326 qp->daddr == qp_in->daddr &&
327 qp->protocol == qp_in->protocol && 327 qp->protocol == qp_in->protocol &&
328 qp->user == qp_in->user) { 328 qp->user == qp_in->user) {
329 atomic_inc(&qp->refcnt); 329 atomic_inc(&qp->refcnt);
330 write_unlock(&ipfrag_lock); 330 write_unlock(&ipfrag_lock);
331 qp_in->last_in |= COMPLETE; 331 qp_in->last_in |= COMPLETE;
@@ -398,11 +398,11 @@ static inline struct ipq *ip_find(struct iphdr *iph, u32 user)
398 read_lock(&ipfrag_lock); 398 read_lock(&ipfrag_lock);
399 hash = ipqhashfn(id, saddr, daddr, protocol); 399 hash = ipqhashfn(id, saddr, daddr, protocol);
400 hlist_for_each_entry(qp, n, &ipq_hash[hash], list) { 400 hlist_for_each_entry(qp, n, &ipq_hash[hash], list) {
401 if(qp->id == id && 401 if (qp->id == id &&
402 qp->saddr == saddr && 402 qp->saddr == saddr &&
403 qp->daddr == daddr && 403 qp->daddr == daddr &&
404 qp->protocol == protocol && 404 qp->protocol == protocol &&
405 qp->user == user) { 405 qp->user == user) {
406 atomic_inc(&qp->refcnt); 406 atomic_inc(&qp->refcnt);
407 read_unlock(&ipfrag_lock); 407 read_unlock(&ipfrag_lock);
408 return qp; 408 return qp;
@@ -524,7 +524,7 @@ static void ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
524 * this fragment, right? 524 * this fragment, right?
525 */ 525 */
526 prev = NULL; 526 prev = NULL;
527 for(next = qp->fragments; next != NULL; next = next->next) { 527 for (next = qp->fragments; next != NULL; next = next->next) {
528 if (FRAG_CB(next)->offset >= offset) 528 if (FRAG_CB(next)->offset >= offset)
529 break; /* bingo! */ 529 break; /* bingo! */
530 prev = next; 530 prev = next;
@@ -627,7 +627,7 @@ static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
627 ihlen = head->nh.iph->ihl*4; 627 ihlen = head->nh.iph->ihl*4;
628 len = ihlen + qp->len; 628 len = ihlen + qp->len;
629 629
630 if(len > 65535) 630 if (len > 65535)
631 goto out_oversize; 631 goto out_oversize;
632 632
633 /* Head of list must not be cloned. */ 633 /* Head of list must not be cloned. */
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index d096332f6c6d..5db301b33372 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -566,7 +566,7 @@ slow_path:
566 * Keep copying data until we run out. 566 * Keep copying data until we run out.
567 */ 567 */
568 568
569 while(left > 0) { 569 while (left > 0) {
570 len = left; 570 len = left;
571 /* IF: it doesn't fit, use 'mtu' - the data space left */ 571 /* IF: it doesn't fit, use 'mtu' - the data space left */
572 if (len > mtu) 572 if (len > mtu)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 23048d9f3584..c5e41644c80d 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -403,20 +403,20 @@ out:
403 */ 403 */
404 404
405static int do_ip_setsockopt(struct sock *sk, int level, 405static int do_ip_setsockopt(struct sock *sk, int level,
406 int optname, char __user *optval, int optlen) 406 int optname, char __user *optval, int optlen)
407{ 407{
408 struct inet_sock *inet = inet_sk(sk); 408 struct inet_sock *inet = inet_sk(sk);
409 int val=0,err; 409 int val=0,err;
410 410
411 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) | 411 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) |
412 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) | 412 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) |
413 (1<<IP_RETOPTS) | (1<<IP_TOS) | 413 (1<<IP_RETOPTS) | (1<<IP_TOS) |
414 (1<<IP_TTL) | (1<<IP_HDRINCL) | 414 (1<<IP_TTL) | (1<<IP_HDRINCL) |
415 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) | 415 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
416 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | 416 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
417 (1<<IP_PASSSEC))) || 417 (1<<IP_PASSSEC))) ||
418 optname == IP_MULTICAST_TTL || 418 optname == IP_MULTICAST_TTL ||
419 optname == IP_MULTICAST_LOOP) { 419 optname == IP_MULTICAST_LOOP) {
420 if (optlen >= sizeof(int)) { 420 if (optlen >= sizeof(int)) {
421 if (get_user(val, (int __user *) optval)) 421 if (get_user(val, (int __user *) optval))
422 return -EFAULT; 422 return -EFAULT;
@@ -440,444 +440,444 @@ static int do_ip_setsockopt(struct sock *sk, int level,
440 lock_sock(sk); 440 lock_sock(sk);
441 441
442 switch (optname) { 442 switch (optname) {
443 case IP_OPTIONS: 443 case IP_OPTIONS:
444 { 444 {
445 struct ip_options * opt = NULL; 445 struct ip_options * opt = NULL;
446 if (optlen > 40 || optlen < 0) 446 if (optlen > 40 || optlen < 0)
447 goto e_inval; 447 goto e_inval;
448 err = ip_options_get_from_user(&opt, optval, optlen); 448 err = ip_options_get_from_user(&opt, optval, optlen);
449 if (err) 449 if (err)
450 break; 450 break;
451 if (inet->is_icsk) { 451 if (inet->is_icsk) {
452 struct inet_connection_sock *icsk = inet_csk(sk); 452 struct inet_connection_sock *icsk = inet_csk(sk);
453#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 453#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
454 if (sk->sk_family == PF_INET || 454 if (sk->sk_family == PF_INET ||
455 (!((1 << sk->sk_state) & 455 (!((1 << sk->sk_state) &
456 (TCPF_LISTEN | TCPF_CLOSE)) && 456 (TCPF_LISTEN | TCPF_CLOSE)) &&
457 inet->daddr != LOOPBACK4_IPV6)) { 457 inet->daddr != LOOPBACK4_IPV6)) {
458#endif 458#endif
459 if (inet->opt) 459 if (inet->opt)
460 icsk->icsk_ext_hdr_len -= inet->opt->optlen; 460 icsk->icsk_ext_hdr_len -= inet->opt->optlen;
461 if (opt) 461 if (opt)
462 icsk->icsk_ext_hdr_len += opt->optlen; 462 icsk->icsk_ext_hdr_len += opt->optlen;
463 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); 463 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
464#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 464#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
465 }
466#endif
467 } 465 }
468 opt = xchg(&inet->opt, opt); 466#endif
469 kfree(opt);
470 break;
471 } 467 }
472 case IP_PKTINFO: 468 opt = xchg(&inet->opt, opt);
473 if (val) 469 kfree(opt);
474 inet->cmsg_flags |= IP_CMSG_PKTINFO; 470 break;
475 else 471 }
476 inet->cmsg_flags &= ~IP_CMSG_PKTINFO; 472 case IP_PKTINFO:
477 break; 473 if (val)
478 case IP_RECVTTL: 474 inet->cmsg_flags |= IP_CMSG_PKTINFO;
479 if (val) 475 else
480 inet->cmsg_flags |= IP_CMSG_TTL; 476 inet->cmsg_flags &= ~IP_CMSG_PKTINFO;
481 else 477 break;
482 inet->cmsg_flags &= ~IP_CMSG_TTL; 478 case IP_RECVTTL:
483 break; 479 if (val)
484 case IP_RECVTOS: 480 inet->cmsg_flags |= IP_CMSG_TTL;
485 if (val) 481 else
486 inet->cmsg_flags |= IP_CMSG_TOS; 482 inet->cmsg_flags &= ~IP_CMSG_TTL;
487 else 483 break;
488 inet->cmsg_flags &= ~IP_CMSG_TOS; 484 case IP_RECVTOS:
489 break; 485 if (val)
490 case IP_RECVOPTS: 486 inet->cmsg_flags |= IP_CMSG_TOS;
491 if (val) 487 else
492 inet->cmsg_flags |= IP_CMSG_RECVOPTS; 488 inet->cmsg_flags &= ~IP_CMSG_TOS;
493 else 489 break;
494 inet->cmsg_flags &= ~IP_CMSG_RECVOPTS; 490 case IP_RECVOPTS:
495 break; 491 if (val)
496 case IP_RETOPTS: 492 inet->cmsg_flags |= IP_CMSG_RECVOPTS;
497 if (val) 493 else
498 inet->cmsg_flags |= IP_CMSG_RETOPTS; 494 inet->cmsg_flags &= ~IP_CMSG_RECVOPTS;
499 else 495 break;
500 inet->cmsg_flags &= ~IP_CMSG_RETOPTS; 496 case IP_RETOPTS:
497 if (val)
498 inet->cmsg_flags |= IP_CMSG_RETOPTS;
499 else
500 inet->cmsg_flags &= ~IP_CMSG_RETOPTS;
501 break;
502 case IP_PASSSEC:
503 if (val)
504 inet->cmsg_flags |= IP_CMSG_PASSSEC;
505 else
506 inet->cmsg_flags &= ~IP_CMSG_PASSSEC;
507 break;
508 case IP_TOS: /* This sets both TOS and Precedence */
509 if (sk->sk_type == SOCK_STREAM) {
510 val &= ~3;
511 val |= inet->tos & 3;
512 }
513 if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP &&
514 !capable(CAP_NET_ADMIN)) {
515 err = -EPERM;
501 break; 516 break;
502 case IP_PASSSEC: 517 }
503 if (val) 518 if (inet->tos != val) {
504 inet->cmsg_flags |= IP_CMSG_PASSSEC; 519 inet->tos = val;
505 else 520 sk->sk_priority = rt_tos2priority(val);
506 inet->cmsg_flags &= ~IP_CMSG_PASSSEC; 521 sk_dst_reset(sk);
522 }
523 break;
524 case IP_TTL:
525 if (optlen<1)
526 goto e_inval;
527 if (val != -1 && (val < 1 || val>255))
528 goto e_inval;
529 inet->uc_ttl = val;
530 break;
531 case IP_HDRINCL:
532 if (sk->sk_type != SOCK_RAW) {
533 err = -ENOPROTOOPT;
507 break; 534 break;
508 case IP_TOS: /* This sets both TOS and Precedence */ 535 }
509 if (sk->sk_type == SOCK_STREAM) { 536 inet->hdrincl = val ? 1 : 0;
510 val &= ~3; 537 break;
511 val |= inet->tos & 3; 538 case IP_MTU_DISCOVER:
512 } 539 if (val<0 || val>2)
513 if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP && 540 goto e_inval;
514 !capable(CAP_NET_ADMIN)) { 541 inet->pmtudisc = val;
515 err = -EPERM; 542 break;
543 case IP_RECVERR:
544 inet->recverr = !!val;
545 if (!val)
546 skb_queue_purge(&sk->sk_error_queue);
547 break;
548 case IP_MULTICAST_TTL:
549 if (sk->sk_type == SOCK_STREAM)
550 goto e_inval;
551 if (optlen<1)
552 goto e_inval;
553 if (val==-1)
554 val = 1;
555 if (val < 0 || val > 255)
556 goto e_inval;
557 inet->mc_ttl = val;
558 break;
559 case IP_MULTICAST_LOOP:
560 if (optlen<1)
561 goto e_inval;
562 inet->mc_loop = !!val;
563 break;
564 case IP_MULTICAST_IF:
565 {
566 struct ip_mreqn mreq;
567 struct net_device *dev = NULL;
568
569 if (sk->sk_type == SOCK_STREAM)
570 goto e_inval;
571 /*
572 * Check the arguments are allowable
573 */
574
575 err = -EFAULT;
576 if (optlen >= sizeof(struct ip_mreqn)) {
577 if (copy_from_user(&mreq,optval,sizeof(mreq)))
516 break; 578 break;
517 } 579 } else {
518 if (inet->tos != val) { 580 memset(&mreq, 0, sizeof(mreq));
519 inet->tos = val; 581 if (optlen >= sizeof(struct in_addr) &&
520 sk->sk_priority = rt_tos2priority(val); 582 copy_from_user(&mreq.imr_address,optval,sizeof(struct in_addr)))
521 sk_dst_reset(sk); 583 break;
522 } 584 }
523 break; 585
524 case IP_TTL: 586 if (!mreq.imr_ifindex) {
525 if (optlen<1) 587 if (mreq.imr_address.s_addr == INADDR_ANY) {
526 goto e_inval; 588 inet->mc_index = 0;
527 if (val != -1 && (val < 1 || val>255)) 589 inet->mc_addr = 0;
528 goto e_inval; 590 err = 0;
529 inet->uc_ttl = val;
530 break;
531 case IP_HDRINCL:
532 if (sk->sk_type != SOCK_RAW) {
533 err = -ENOPROTOOPT;
534 break; 591 break;
535 } 592 }
536 inet->hdrincl = val ? 1 : 0; 593 dev = ip_dev_find(mreq.imr_address.s_addr);
537 break; 594 if (dev) {
538 case IP_MTU_DISCOVER: 595 mreq.imr_ifindex = dev->ifindex;
539 if (val<0 || val>2) 596 dev_put(dev);
540 goto e_inval; 597 }
541 inet->pmtudisc = val; 598 } else
542 break; 599 dev = __dev_get_by_index(mreq.imr_ifindex);
543 case IP_RECVERR:
544 inet->recverr = !!val;
545 if (!val)
546 skb_queue_purge(&sk->sk_error_queue);
547 break;
548 case IP_MULTICAST_TTL:
549 if (sk->sk_type == SOCK_STREAM)
550 goto e_inval;
551 if (optlen<1)
552 goto e_inval;
553 if (val==-1)
554 val = 1;
555 if (val < 0 || val > 255)
556 goto e_inval;
557 inet->mc_ttl = val;
558 break;
559 case IP_MULTICAST_LOOP:
560 if (optlen<1)
561 goto e_inval;
562 inet->mc_loop = !!val;
563 break;
564 case IP_MULTICAST_IF:
565 {
566 struct ip_mreqn mreq;
567 struct net_device *dev = NULL;
568 600
569 if (sk->sk_type == SOCK_STREAM)
570 goto e_inval;
571 /*
572 * Check the arguments are allowable
573 */
574 601
575 err = -EFAULT; 602 err = -EADDRNOTAVAIL;
576 if (optlen >= sizeof(struct ip_mreqn)) { 603 if (!dev)
577 if (copy_from_user(&mreq,optval,sizeof(mreq))) 604 break;
578 break; 605
579 } else { 606 err = -EINVAL;
580 memset(&mreq, 0, sizeof(mreq)); 607 if (sk->sk_bound_dev_if &&
581 if (optlen >= sizeof(struct in_addr) && 608 mreq.imr_ifindex != sk->sk_bound_dev_if)
582 copy_from_user(&mreq.imr_address,optval,sizeof(struct in_addr))) 609 break;
583 break;
584 }
585 610
586 if (!mreq.imr_ifindex) { 611 inet->mc_index = mreq.imr_ifindex;
587 if (mreq.imr_address.s_addr == INADDR_ANY) { 612 inet->mc_addr = mreq.imr_address.s_addr;
588 inet->mc_index = 0; 613 err = 0;
589 inet->mc_addr = 0; 614 break;
590 err = 0; 615 }
591 break;
592 }
593 dev = ip_dev_find(mreq.imr_address.s_addr);
594 if (dev) {
595 mreq.imr_ifindex = dev->ifindex;
596 dev_put(dev);
597 }
598 } else
599 dev = __dev_get_by_index(mreq.imr_ifindex);
600 616
617 case IP_ADD_MEMBERSHIP:
618 case IP_DROP_MEMBERSHIP:
619 {
620 struct ip_mreqn mreq;
601 621
602 err = -EADDRNOTAVAIL; 622 if (optlen < sizeof(struct ip_mreq))
603 if (!dev) 623 goto e_inval;
624 err = -EFAULT;
625 if (optlen >= sizeof(struct ip_mreqn)) {
626 if (copy_from_user(&mreq,optval,sizeof(mreq)))
604 break; 627 break;
605 628 } else {
606 err = -EINVAL; 629 memset(&mreq, 0, sizeof(mreq));
607 if (sk->sk_bound_dev_if && 630 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq)))
608 mreq.imr_ifindex != sk->sk_bound_dev_if)
609 break; 631 break;
632 }
610 633
611 inet->mc_index = mreq.imr_ifindex; 634 if (optname == IP_ADD_MEMBERSHIP)
612 inet->mc_addr = mreq.imr_address.s_addr; 635 err = ip_mc_join_group(sk, &mreq);
613 err = 0; 636 else
637 err = ip_mc_leave_group(sk, &mreq);
638 break;
639 }
640 case IP_MSFILTER:
641 {
642 extern int sysctl_igmp_max_msf;
643 struct ip_msfilter *msf;
644
645 if (optlen < IP_MSFILTER_SIZE(0))
646 goto e_inval;
647 if (optlen > sysctl_optmem_max) {
648 err = -ENOBUFS;
614 break; 649 break;
615 } 650 }
651 msf = kmalloc(optlen, GFP_KERNEL);
652 if (msf == 0) {
653 err = -ENOBUFS;
654 break;
655 }
656 err = -EFAULT;
657 if (copy_from_user(msf, optval, optlen)) {
658 kfree(msf);
659 break;
660 }
661 /* numsrc >= (1G-4) overflow in 32 bits */
662 if (msf->imsf_numsrc >= 0x3ffffffcU ||
663 msf->imsf_numsrc > sysctl_igmp_max_msf) {
664 kfree(msf);
665 err = -ENOBUFS;
666 break;
667 }
668 if (IP_MSFILTER_SIZE(msf->imsf_numsrc) > optlen) {
669 kfree(msf);
670 err = -EINVAL;
671 break;
672 }
673 err = ip_mc_msfilter(sk, msf, 0);
674 kfree(msf);
675 break;
676 }
677 case IP_BLOCK_SOURCE:
678 case IP_UNBLOCK_SOURCE:
679 case IP_ADD_SOURCE_MEMBERSHIP:
680 case IP_DROP_SOURCE_MEMBERSHIP:
681 {
682 struct ip_mreq_source mreqs;
683 int omode, add;
616 684
617 case IP_ADD_MEMBERSHIP: 685 if (optlen != sizeof(struct ip_mreq_source))
618 case IP_DROP_MEMBERSHIP: 686 goto e_inval;
619 { 687 if (copy_from_user(&mreqs, optval, sizeof(mreqs))) {
620 struct ip_mreqn mreq;
621
622 if (optlen < sizeof(struct ip_mreq))
623 goto e_inval;
624 err = -EFAULT; 688 err = -EFAULT;
625 if (optlen >= sizeof(struct ip_mreqn)) {
626 if(copy_from_user(&mreq,optval,sizeof(mreq)))
627 break;
628 } else {
629 memset(&mreq, 0, sizeof(mreq));
630 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq)))
631 break;
632 }
633
634 if (optname == IP_ADD_MEMBERSHIP)
635 err = ip_mc_join_group(sk, &mreq);
636 else
637 err = ip_mc_leave_group(sk, &mreq);
638 break; 689 break;
639 } 690 }
640 case IP_MSFILTER: 691 if (optname == IP_BLOCK_SOURCE) {
641 { 692 omode = MCAST_EXCLUDE;
642 extern int sysctl_igmp_max_msf; 693 add = 1;
643 struct ip_msfilter *msf; 694 } else if (optname == IP_UNBLOCK_SOURCE) {
695 omode = MCAST_EXCLUDE;
696 add = 0;
697 } else if (optname == IP_ADD_SOURCE_MEMBERSHIP) {
698 struct ip_mreqn mreq;
644 699
645 if (optlen < IP_MSFILTER_SIZE(0)) 700 mreq.imr_multiaddr.s_addr = mreqs.imr_multiaddr;
646 goto e_inval; 701 mreq.imr_address.s_addr = mreqs.imr_interface;
647 if (optlen > sysctl_optmem_max) { 702 mreq.imr_ifindex = 0;
648 err = -ENOBUFS; 703 err = ip_mc_join_group(sk, &mreq);
649 break; 704 if (err && err != -EADDRINUSE)
650 }
651 msf = kmalloc(optlen, GFP_KERNEL);
652 if (msf == 0) {
653 err = -ENOBUFS;
654 break; 705 break;
655 } 706 omode = MCAST_INCLUDE;
707 add = 1;
708 } else /* IP_DROP_SOURCE_MEMBERSHIP */ {
709 omode = MCAST_INCLUDE;
710 add = 0;
711 }
712 err = ip_mc_source(add, omode, sk, &mreqs, 0);
713 break;
714 }
715 case MCAST_JOIN_GROUP:
716 case MCAST_LEAVE_GROUP:
717 {
718 struct group_req greq;
719 struct sockaddr_in *psin;
720 struct ip_mreqn mreq;
721
722 if (optlen < sizeof(struct group_req))
723 goto e_inval;
724 err = -EFAULT;
725 if (copy_from_user(&greq, optval, sizeof(greq)))
726 break;
727 psin = (struct sockaddr_in *)&greq.gr_group;
728 if (psin->sin_family != AF_INET)
729 goto e_inval;
730 memset(&mreq, 0, sizeof(mreq));
731 mreq.imr_multiaddr = psin->sin_addr;
732 mreq.imr_ifindex = greq.gr_interface;
733
734 if (optname == MCAST_JOIN_GROUP)
735 err = ip_mc_join_group(sk, &mreq);
736 else
737 err = ip_mc_leave_group(sk, &mreq);
738 break;
739 }
740 case MCAST_JOIN_SOURCE_GROUP:
741 case MCAST_LEAVE_SOURCE_GROUP:
742 case MCAST_BLOCK_SOURCE:
743 case MCAST_UNBLOCK_SOURCE:
744 {
745 struct group_source_req greqs;
746 struct ip_mreq_source mreqs;
747 struct sockaddr_in *psin;
748 int omode, add;
749
750 if (optlen != sizeof(struct group_source_req))
751 goto e_inval;
752 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
656 err = -EFAULT; 753 err = -EFAULT;
657 if (copy_from_user(msf, optval, optlen)) {
658 kfree(msf);
659 break;
660 }
661 /* numsrc >= (1G-4) overflow in 32 bits */
662 if (msf->imsf_numsrc >= 0x3ffffffcU ||
663 msf->imsf_numsrc > sysctl_igmp_max_msf) {
664 kfree(msf);
665 err = -ENOBUFS;
666 break;
667 }
668 if (IP_MSFILTER_SIZE(msf->imsf_numsrc) > optlen) {
669 kfree(msf);
670 err = -EINVAL;
671 break;
672 }
673 err = ip_mc_msfilter(sk, msf, 0);
674 kfree(msf);
675 break; 754 break;
676 } 755 }
677 case IP_BLOCK_SOURCE: 756 if (greqs.gsr_group.ss_family != AF_INET ||
678 case IP_UNBLOCK_SOURCE: 757 greqs.gsr_source.ss_family != AF_INET) {
679 case IP_ADD_SOURCE_MEMBERSHIP: 758 err = -EADDRNOTAVAIL;
680 case IP_DROP_SOURCE_MEMBERSHIP:
681 {
682 struct ip_mreq_source mreqs;
683 int omode, add;
684
685 if (optlen != sizeof(struct ip_mreq_source))
686 goto e_inval;
687 if (copy_from_user(&mreqs, optval, sizeof(mreqs))) {
688 err = -EFAULT;
689 break;
690 }
691 if (optname == IP_BLOCK_SOURCE) {
692 omode = MCAST_EXCLUDE;
693 add = 1;
694 } else if (optname == IP_UNBLOCK_SOURCE) {
695 omode = MCAST_EXCLUDE;
696 add = 0;
697 } else if (optname == IP_ADD_SOURCE_MEMBERSHIP) {
698 struct ip_mreqn mreq;
699
700 mreq.imr_multiaddr.s_addr = mreqs.imr_multiaddr;
701 mreq.imr_address.s_addr = mreqs.imr_interface;
702 mreq.imr_ifindex = 0;
703 err = ip_mc_join_group(sk, &mreq);
704 if (err && err != -EADDRINUSE)
705 break;
706 omode = MCAST_INCLUDE;
707 add = 1;
708 } else /* IP_DROP_SOURCE_MEMBERSHIP */ {
709 omode = MCAST_INCLUDE;
710 add = 0;
711 }
712 err = ip_mc_source(add, omode, sk, &mreqs, 0);
713 break; 759 break;
714 } 760 }
715 case MCAST_JOIN_GROUP: 761 psin = (struct sockaddr_in *)&greqs.gsr_group;
716 case MCAST_LEAVE_GROUP: 762 mreqs.imr_multiaddr = psin->sin_addr.s_addr;
717 { 763 psin = (struct sockaddr_in *)&greqs.gsr_source;
718 struct group_req greq; 764 mreqs.imr_sourceaddr = psin->sin_addr.s_addr;
719 struct sockaddr_in *psin; 765 mreqs.imr_interface = 0; /* use index for mc_source */
766
767 if (optname == MCAST_BLOCK_SOURCE) {
768 omode = MCAST_EXCLUDE;
769 add = 1;
770 } else if (optname == MCAST_UNBLOCK_SOURCE) {
771 omode = MCAST_EXCLUDE;
772 add = 0;
773 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
720 struct ip_mreqn mreq; 774 struct ip_mreqn mreq;
721 775
722 if (optlen < sizeof(struct group_req)) 776 psin = (struct sockaddr_in *)&greqs.gsr_group;
723 goto e_inval;
724 err = -EFAULT;
725 if(copy_from_user(&greq, optval, sizeof(greq)))
726 break;
727 psin = (struct sockaddr_in *)&greq.gr_group;
728 if (psin->sin_family != AF_INET)
729 goto e_inval;
730 memset(&mreq, 0, sizeof(mreq));
731 mreq.imr_multiaddr = psin->sin_addr; 777 mreq.imr_multiaddr = psin->sin_addr;
732 mreq.imr_ifindex = greq.gr_interface; 778 mreq.imr_address.s_addr = 0;
733 779 mreq.imr_ifindex = greqs.gsr_interface;
734 if (optname == MCAST_JOIN_GROUP) 780 err = ip_mc_join_group(sk, &mreq);
735 err = ip_mc_join_group(sk, &mreq); 781 if (err && err != -EADDRINUSE)
736 else 782 break;
737 err = ip_mc_leave_group(sk, &mreq); 783 greqs.gsr_interface = mreq.imr_ifindex;
784 omode = MCAST_INCLUDE;
785 add = 1;
786 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
787 omode = MCAST_INCLUDE;
788 add = 0;
789 }
790 err = ip_mc_source(add, omode, sk, &mreqs,
791 greqs.gsr_interface);
792 break;
793 }
794 case MCAST_MSFILTER:
795 {
796 extern int sysctl_igmp_max_msf;
797 struct sockaddr_in *psin;
798 struct ip_msfilter *msf = NULL;
799 struct group_filter *gsf = NULL;
800 int msize, i, ifindex;
801
802 if (optlen < GROUP_FILTER_SIZE(0))
803 goto e_inval;
804 if (optlen > sysctl_optmem_max) {
805 err = -ENOBUFS;
738 break; 806 break;
739 } 807 }
740 case MCAST_JOIN_SOURCE_GROUP: 808 gsf = kmalloc(optlen,GFP_KERNEL);
741 case MCAST_LEAVE_SOURCE_GROUP: 809 if (gsf == 0) {
742 case MCAST_BLOCK_SOURCE: 810 err = -ENOBUFS;
743 case MCAST_UNBLOCK_SOURCE:
744 {
745 struct group_source_req greqs;
746 struct ip_mreq_source mreqs;
747 struct sockaddr_in *psin;
748 int omode, add;
749
750 if (optlen != sizeof(struct group_source_req))
751 goto e_inval;
752 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
753 err = -EFAULT;
754 break;
755 }
756 if (greqs.gsr_group.ss_family != AF_INET ||
757 greqs.gsr_source.ss_family != AF_INET) {
758 err = -EADDRNOTAVAIL;
759 break;
760 }
761 psin = (struct sockaddr_in *)&greqs.gsr_group;
762 mreqs.imr_multiaddr = psin->sin_addr.s_addr;
763 psin = (struct sockaddr_in *)&greqs.gsr_source;
764 mreqs.imr_sourceaddr = psin->sin_addr.s_addr;
765 mreqs.imr_interface = 0; /* use index for mc_source */
766
767 if (optname == MCAST_BLOCK_SOURCE) {
768 omode = MCAST_EXCLUDE;
769 add = 1;
770 } else if (optname == MCAST_UNBLOCK_SOURCE) {
771 omode = MCAST_EXCLUDE;
772 add = 0;
773 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
774 struct ip_mreqn mreq;
775
776 psin = (struct sockaddr_in *)&greqs.gsr_group;
777 mreq.imr_multiaddr = psin->sin_addr;
778 mreq.imr_address.s_addr = 0;
779 mreq.imr_ifindex = greqs.gsr_interface;
780 err = ip_mc_join_group(sk, &mreq);
781 if (err && err != -EADDRINUSE)
782 break;
783 greqs.gsr_interface = mreq.imr_ifindex;
784 omode = MCAST_INCLUDE;
785 add = 1;
786 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
787 omode = MCAST_INCLUDE;
788 add = 0;
789 }
790 err = ip_mc_source(add, omode, sk, &mreqs,
791 greqs.gsr_interface);
792 break; 811 break;
793 } 812 }
794 case MCAST_MSFILTER: 813 err = -EFAULT;
795 { 814 if (copy_from_user(gsf, optval, optlen)) {
796 extern int sysctl_igmp_max_msf; 815 goto mc_msf_out;
797 struct sockaddr_in *psin; 816 }
798 struct ip_msfilter *msf = NULL; 817 /* numsrc >= (4G-140)/128 overflow in 32 bits */
799 struct group_filter *gsf = NULL; 818 if (gsf->gf_numsrc >= 0x1ffffff ||
800 int msize, i, ifindex; 819 gsf->gf_numsrc > sysctl_igmp_max_msf) {
801 820 err = -ENOBUFS;
802 if (optlen < GROUP_FILTER_SIZE(0)) 821 goto mc_msf_out;
803 goto e_inval; 822 }
804 if (optlen > sysctl_optmem_max) { 823 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
805 err = -ENOBUFS; 824 err = -EINVAL;
806 break; 825 goto mc_msf_out;
807 } 826 }
808 gsf = kmalloc(optlen,GFP_KERNEL); 827 msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
809 if (gsf == 0) { 828 msf = kmalloc(msize,GFP_KERNEL);
810 err = -ENOBUFS; 829 if (msf == 0) {
811 break; 830 err = -ENOBUFS;
812 } 831 goto mc_msf_out;
813 err = -EFAULT; 832 }
814 if (copy_from_user(gsf, optval, optlen)) { 833 ifindex = gsf->gf_interface;
815 goto mc_msf_out; 834 psin = (struct sockaddr_in *)&gsf->gf_group;
816 } 835 if (psin->sin_family != AF_INET) {
817 /* numsrc >= (4G-140)/128 overflow in 32 bits */
818 if (gsf->gf_numsrc >= 0x1ffffff ||
819 gsf->gf_numsrc > sysctl_igmp_max_msf) {
820 err = -ENOBUFS;
821 goto mc_msf_out;
822 }
823 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
824 err = -EINVAL;
825 goto mc_msf_out;
826 }
827 msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
828 msf = kmalloc(msize,GFP_KERNEL);
829 if (msf == 0) {
830 err = -ENOBUFS;
831 goto mc_msf_out;
832 }
833 ifindex = gsf->gf_interface;
834 psin = (struct sockaddr_in *)&gsf->gf_group;
835 if (psin->sin_family != AF_INET) {
836 err = -EADDRNOTAVAIL;
837 goto mc_msf_out;
838 }
839 msf->imsf_multiaddr = psin->sin_addr.s_addr;
840 msf->imsf_interface = 0;
841 msf->imsf_fmode = gsf->gf_fmode;
842 msf->imsf_numsrc = gsf->gf_numsrc;
843 err = -EADDRNOTAVAIL; 836 err = -EADDRNOTAVAIL;
844 for (i=0; i<gsf->gf_numsrc; ++i) { 837 goto mc_msf_out;
845 psin = (struct sockaddr_in *)&gsf->gf_slist[i];
846
847 if (psin->sin_family != AF_INET)
848 goto mc_msf_out;
849 msf->imsf_slist[i] = psin->sin_addr.s_addr;
850 }
851 kfree(gsf);
852 gsf = NULL;
853
854 err = ip_mc_msfilter(sk, msf, ifindex);
855mc_msf_out:
856 kfree(msf);
857 kfree(gsf);
858 break;
859 } 838 }
860 case IP_ROUTER_ALERT: 839 msf->imsf_multiaddr = psin->sin_addr.s_addr;
861 err = ip_ra_control(sk, val ? 1 : 0, NULL); 840 msf->imsf_interface = 0;
862 break; 841 msf->imsf_fmode = gsf->gf_fmode;
842 msf->imsf_numsrc = gsf->gf_numsrc;
843 err = -EADDRNOTAVAIL;
844 for (i=0; i<gsf->gf_numsrc; ++i) {
845 psin = (struct sockaddr_in *)&gsf->gf_slist[i];
863 846
864 case IP_FREEBIND: 847 if (psin->sin_family != AF_INET)
865 if (optlen<1) 848 goto mc_msf_out;
866 goto e_inval; 849 msf->imsf_slist[i] = psin->sin_addr.s_addr;
867 inet->freebind = !!val; 850 }
868 break; 851 kfree(gsf);
869 852 gsf = NULL;
870 case IP_IPSEC_POLICY: 853
871 case IP_XFRM_POLICY: 854 err = ip_mc_msfilter(sk, msf, ifindex);
872 err = -EPERM; 855 mc_msf_out:
873 if (!capable(CAP_NET_ADMIN)) 856 kfree(msf);
874 break; 857 kfree(gsf);
875 err = xfrm_user_policy(sk, optname, optval, optlen); 858 break;
859 }
860 case IP_ROUTER_ALERT:
861 err = ip_ra_control(sk, val ? 1 : 0, NULL);
862 break;
863
864 case IP_FREEBIND:
865 if (optlen<1)
866 goto e_inval;
867 inet->freebind = !!val;
868 break;
869
870 case IP_IPSEC_POLICY:
871 case IP_XFRM_POLICY:
872 err = -EPERM;
873 if (!capable(CAP_NET_ADMIN))
876 break; 874 break;
875 err = xfrm_user_policy(sk, optname, optval, optlen);
876 break;
877 877
878 default: 878 default:
879 err = -ENOPROTOOPT; 879 err = -ENOPROTOOPT;
880 break; 880 break;
881 } 881 }
882 release_sock(sk); 882 release_sock(sk);
883 return err; 883 return err;
@@ -948,214 +948,213 @@ EXPORT_SYMBOL(compat_ip_setsockopt);
948 */ 948 */
949 949
950static int do_ip_getsockopt(struct sock *sk, int level, int optname, 950static int do_ip_getsockopt(struct sock *sk, int level, int optname,
951 char __user *optval, int __user *optlen) 951 char __user *optval, int __user *optlen)
952{ 952{
953 struct inet_sock *inet = inet_sk(sk); 953 struct inet_sock *inet = inet_sk(sk);
954 int val; 954 int val;
955 int len; 955 int len;
956 956
957 if(level!=SOL_IP) 957 if (level != SOL_IP)
958 return -EOPNOTSUPP; 958 return -EOPNOTSUPP;
959 959
960#ifdef CONFIG_IP_MROUTE 960#ifdef CONFIG_IP_MROUTE
961 if(optname>=MRT_BASE && optname <=MRT_BASE+10) 961 if (optname >= MRT_BASE && optname <= MRT_BASE+10) {
962 {
963 return ip_mroute_getsockopt(sk,optname,optval,optlen); 962 return ip_mroute_getsockopt(sk,optname,optval,optlen);
964 } 963 }
965#endif 964#endif
966 965
967 if(get_user(len,optlen)) 966 if (get_user(len,optlen))
968 return -EFAULT; 967 return -EFAULT;
969 if(len < 0) 968 if (len < 0)
970 return -EINVAL; 969 return -EINVAL;
971 970
972 lock_sock(sk); 971 lock_sock(sk);
973 972
974 switch(optname) { 973 switch (optname) {
975 case IP_OPTIONS: 974 case IP_OPTIONS:
976 { 975 {
977 unsigned char optbuf[sizeof(struct ip_options)+40]; 976 unsigned char optbuf[sizeof(struct ip_options)+40];
978 struct ip_options * opt = (struct ip_options*)optbuf; 977 struct ip_options * opt = (struct ip_options*)optbuf;
979 opt->optlen = 0; 978 opt->optlen = 0;
980 if (inet->opt) 979 if (inet->opt)
981 memcpy(optbuf, inet->opt, 980 memcpy(optbuf, inet->opt,
982 sizeof(struct ip_options)+ 981 sizeof(struct ip_options)+
983 inet->opt->optlen); 982 inet->opt->optlen);
984 release_sock(sk); 983 release_sock(sk);
985 984
986 if (opt->optlen == 0) 985 if (opt->optlen == 0)
987 return put_user(0, optlen); 986 return put_user(0, optlen);
988 987
989 ip_options_undo(opt); 988 ip_options_undo(opt);
990 989
991 len = min_t(unsigned int, len, opt->optlen); 990 len = min_t(unsigned int, len, opt->optlen);
992 if(put_user(len, optlen)) 991 if (put_user(len, optlen))
993 return -EFAULT; 992 return -EFAULT;
994 if(copy_to_user(optval, opt->__data, len)) 993 if (copy_to_user(optval, opt->__data, len))
995 return -EFAULT; 994 return -EFAULT;
996 return 0; 995 return 0;
997 } 996 }
998 case IP_PKTINFO: 997 case IP_PKTINFO:
999 val = (inet->cmsg_flags & IP_CMSG_PKTINFO) != 0; 998 val = (inet->cmsg_flags & IP_CMSG_PKTINFO) != 0;
1000 break; 999 break;
1001 case IP_RECVTTL: 1000 case IP_RECVTTL:
1002 val = (inet->cmsg_flags & IP_CMSG_TTL) != 0; 1001 val = (inet->cmsg_flags & IP_CMSG_TTL) != 0;
1003 break; 1002 break;
1004 case IP_RECVTOS: 1003 case IP_RECVTOS:
1005 val = (inet->cmsg_flags & IP_CMSG_TOS) != 0; 1004 val = (inet->cmsg_flags & IP_CMSG_TOS) != 0;
1006 break; 1005 break;
1007 case IP_RECVOPTS: 1006 case IP_RECVOPTS:
1008 val = (inet->cmsg_flags & IP_CMSG_RECVOPTS) != 0; 1007 val = (inet->cmsg_flags & IP_CMSG_RECVOPTS) != 0;
1009 break; 1008 break;
1010 case IP_RETOPTS: 1009 case IP_RETOPTS:
1011 val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0; 1010 val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0;
1012 break; 1011 break;
1013 case IP_PASSSEC: 1012 case IP_PASSSEC:
1014 val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0; 1013 val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0;
1015 break; 1014 break;
1016 case IP_TOS: 1015 case IP_TOS:
1017 val = inet->tos; 1016 val = inet->tos;
1018 break; 1017 break;
1019 case IP_TTL: 1018 case IP_TTL:
1020 val = (inet->uc_ttl == -1 ? 1019 val = (inet->uc_ttl == -1 ?
1021 sysctl_ip_default_ttl : 1020 sysctl_ip_default_ttl :
1022 inet->uc_ttl); 1021 inet->uc_ttl);
1023 break; 1022 break;
1024 case IP_HDRINCL: 1023 case IP_HDRINCL:
1025 val = inet->hdrincl; 1024 val = inet->hdrincl;
1026 break; 1025 break;
1027 case IP_MTU_DISCOVER: 1026 case IP_MTU_DISCOVER:
1028 val = inet->pmtudisc; 1027 val = inet->pmtudisc;
1029 break; 1028 break;
1030 case IP_MTU: 1029 case IP_MTU:
1031 { 1030 {
1032 struct dst_entry *dst; 1031 struct dst_entry *dst;
1033 val = 0; 1032 val = 0;
1034 dst = sk_dst_get(sk); 1033 dst = sk_dst_get(sk);
1035 if (dst) { 1034 if (dst) {
1036 val = dst_mtu(dst); 1035 val = dst_mtu(dst);
1037 dst_release(dst); 1036 dst_release(dst);
1038 }
1039 if (!val) {
1040 release_sock(sk);
1041 return -ENOTCONN;
1042 }
1043 break;
1044 } 1037 }
1045 case IP_RECVERR: 1038 if (!val) {
1046 val = inet->recverr;
1047 break;
1048 case IP_MULTICAST_TTL:
1049 val = inet->mc_ttl;
1050 break;
1051 case IP_MULTICAST_LOOP:
1052 val = inet->mc_loop;
1053 break;
1054 case IP_MULTICAST_IF:
1055 {
1056 struct in_addr addr;
1057 len = min_t(unsigned int, len, sizeof(struct in_addr));
1058 addr.s_addr = inet->mc_addr;
1059 release_sock(sk); 1039 release_sock(sk);
1060 1040 return -ENOTCONN;
1061 if(put_user(len, optlen))
1062 return -EFAULT;
1063 if(copy_to_user(optval, &addr, len))
1064 return -EFAULT;
1065 return 0;
1066 } 1041 }
1067 case IP_MSFILTER: 1042 break;
1068 { 1043 }
1069 struct ip_msfilter msf; 1044 case IP_RECVERR:
1070 int err; 1045 val = inet->recverr;
1046 break;
1047 case IP_MULTICAST_TTL:
1048 val = inet->mc_ttl;
1049 break;
1050 case IP_MULTICAST_LOOP:
1051 val = inet->mc_loop;
1052 break;
1053 case IP_MULTICAST_IF:
1054 {
1055 struct in_addr addr;
1056 len = min_t(unsigned int, len, sizeof(struct in_addr));
1057 addr.s_addr = inet->mc_addr;
1058 release_sock(sk);
1071 1059
1072 if (len < IP_MSFILTER_SIZE(0)) { 1060 if (put_user(len, optlen))
1073 release_sock(sk); 1061 return -EFAULT;
1074 return -EINVAL; 1062 if (copy_to_user(optval, &addr, len))
1075 } 1063 return -EFAULT;
1076 if (copy_from_user(&msf, optval, IP_MSFILTER_SIZE(0))) { 1064 return 0;
1077 release_sock(sk); 1065 }
1078 return -EFAULT; 1066 case IP_MSFILTER:
1079 } 1067 {
1080 err = ip_mc_msfget(sk, &msf, 1068 struct ip_msfilter msf;
1081 (struct ip_msfilter __user *)optval, optlen); 1069 int err;
1070
1071 if (len < IP_MSFILTER_SIZE(0)) {
1082 release_sock(sk); 1072 release_sock(sk);
1083 return err; 1073 return -EINVAL;
1084 } 1074 }
1085 case MCAST_MSFILTER: 1075 if (copy_from_user(&msf, optval, IP_MSFILTER_SIZE(0))) {
1086 {
1087 struct group_filter gsf;
1088 int err;
1089
1090 if (len < GROUP_FILTER_SIZE(0)) {
1091 release_sock(sk);
1092 return -EINVAL;
1093 }
1094 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) {
1095 release_sock(sk);
1096 return -EFAULT;
1097 }
1098 err = ip_mc_gsfget(sk, &gsf,
1099 (struct group_filter __user *)optval, optlen);
1100 release_sock(sk); 1076 release_sock(sk);
1101 return err; 1077 return -EFAULT;
1102 } 1078 }
1103 case IP_PKTOPTIONS: 1079 err = ip_mc_msfget(sk, &msf,
1104 { 1080 (struct ip_msfilter __user *)optval, optlen);
1105 struct msghdr msg; 1081 release_sock(sk);
1082 return err;
1083 }
1084 case MCAST_MSFILTER:
1085 {
1086 struct group_filter gsf;
1087 int err;
1106 1088
1089 if (len < GROUP_FILTER_SIZE(0)) {
1107 release_sock(sk); 1090 release_sock(sk);
1091 return -EINVAL;
1092 }
1093 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) {
1094 release_sock(sk);
1095 return -EFAULT;
1096 }
1097 err = ip_mc_gsfget(sk, &gsf,
1098 (struct group_filter __user *)optval, optlen);
1099 release_sock(sk);
1100 return err;
1101 }
1102 case IP_PKTOPTIONS:
1103 {
1104 struct msghdr msg;
1105
1106 release_sock(sk);
1108 1107
1109 if (sk->sk_type != SOCK_STREAM) 1108 if (sk->sk_type != SOCK_STREAM)
1110 return -ENOPROTOOPT; 1109 return -ENOPROTOOPT;
1111 1110
1112 msg.msg_control = optval; 1111 msg.msg_control = optval;
1113 msg.msg_controllen = len; 1112 msg.msg_controllen = len;
1114 msg.msg_flags = 0; 1113 msg.msg_flags = 0;
1115 1114
1116 if (inet->cmsg_flags & IP_CMSG_PKTINFO) { 1115 if (inet->cmsg_flags & IP_CMSG_PKTINFO) {
1117 struct in_pktinfo info; 1116 struct in_pktinfo info;
1118 1117
1119 info.ipi_addr.s_addr = inet->rcv_saddr; 1118 info.ipi_addr.s_addr = inet->rcv_saddr;
1120 info.ipi_spec_dst.s_addr = inet->rcv_saddr; 1119 info.ipi_spec_dst.s_addr = inet->rcv_saddr;
1121 info.ipi_ifindex = inet->mc_index; 1120 info.ipi_ifindex = inet->mc_index;
1122 put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info); 1121 put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
1123 }
1124 if (inet->cmsg_flags & IP_CMSG_TTL) {
1125 int hlim = inet->mc_ttl;
1126 put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim);
1127 }
1128 len -= msg.msg_controllen;
1129 return put_user(len, optlen);
1130 } 1122 }
1131 case IP_FREEBIND: 1123 if (inet->cmsg_flags & IP_CMSG_TTL) {
1132 val = inet->freebind; 1124 int hlim = inet->mc_ttl;
1133 break; 1125 put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim);
1134 default: 1126 }
1135 release_sock(sk); 1127 len -= msg.msg_controllen;
1136 return -ENOPROTOOPT; 1128 return put_user(len, optlen);
1129 }
1130 case IP_FREEBIND:
1131 val = inet->freebind;
1132 break;
1133 default:
1134 release_sock(sk);
1135 return -ENOPROTOOPT;
1137 } 1136 }
1138 release_sock(sk); 1137 release_sock(sk);
1139 1138
1140 if (len < sizeof(int) && len > 0 && val>=0 && val<255) { 1139 if (len < sizeof(int) && len > 0 && val>=0 && val<255) {
1141 unsigned char ucval = (unsigned char)val; 1140 unsigned char ucval = (unsigned char)val;
1142 len = 1; 1141 len = 1;
1143 if(put_user(len, optlen)) 1142 if (put_user(len, optlen))
1144 return -EFAULT; 1143 return -EFAULT;
1145 if(copy_to_user(optval,&ucval,1)) 1144 if (copy_to_user(optval,&ucval,1))
1146 return -EFAULT; 1145 return -EFAULT;
1147 } else { 1146 } else {
1148 len = min_t(unsigned int, sizeof(int), len); 1147 len = min_t(unsigned int, sizeof(int), len);
1149 if(put_user(len, optlen)) 1148 if (put_user(len, optlen))
1150 return -EFAULT; 1149 return -EFAULT;
1151 if(copy_to_user(optval,&val,len)) 1150 if (copy_to_user(optval,&val,len))
1152 return -EFAULT; 1151 return -EFAULT;
1153 } 1152 }
1154 return 0; 1153 return 0;
1155} 1154}
1156 1155
1157int ip_getsockopt(struct sock *sk, int level, 1156int ip_getsockopt(struct sock *sk, int level,
1158 int optname, char __user *optval, int __user *optlen) 1157 int optname, char __user *optval, int __user *optlen)
1159{ 1158{
1160 int err; 1159 int err;
1161 1160
@@ -1169,7 +1168,7 @@ int ip_getsockopt(struct sock *sk, int level,
1169 ) { 1168 ) {
1170 int len; 1169 int len;
1171 1170
1172 if(get_user(len,optlen)) 1171 if (get_user(len,optlen))
1173 return -EFAULT; 1172 return -EFAULT;
1174 1173
1175 lock_sock(sk); 1174 lock_sock(sk);
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index cf49de1a4983..c43699f374cd 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -782,7 +782,7 @@ static void __init ic_do_bootp_ext(u8 *ext)
782 u8 *c; 782 u8 *c;
783 783
784 printk("DHCP/BOOTP: Got extension %d:",*ext); 784 printk("DHCP/BOOTP: Got extension %d:",*ext);
785 for(c=ext+2; c<ext+2+ext[1]; c++) 785 for (c=ext+2; c<ext+2+ext[1]; c++)
786 printk(" %02x", *c); 786 printk(" %02x", *c);
787 printk("\n"); 787 printk("\n");
788#endif 788#endif
@@ -1094,7 +1094,7 @@ static int __init ic_dynamic(void)
1094 retries = CONF_SEND_RETRIES; 1094 retries = CONF_SEND_RETRIES;
1095 get_random_bytes(&timeout, sizeof(timeout)); 1095 get_random_bytes(&timeout, sizeof(timeout));
1096 timeout = CONF_BASE_TIMEOUT + (timeout % (unsigned) CONF_TIMEOUT_RANDOM); 1096 timeout = CONF_BASE_TIMEOUT + (timeout % (unsigned) CONF_TIMEOUT_RANDOM);
1097 for(;;) { 1097 for (;;) {
1098#ifdef IPCONFIG_BOOTP 1098#ifdef IPCONFIG_BOOTP
1099 if (do_bootp && (d->able & IC_BOOTP)) 1099 if (do_bootp && (d->able & IC_BOOTP))
1100 ic_bootp_send_if(d, jiffies - start_jiffies); 1100 ic_bootp_send_if(d, jiffies - start_jiffies);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 601e3df69258..f73f4e402f72 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -302,7 +302,7 @@ static void ipmr_destroy_unres(struct mfc_cache *c)
302 302
303 atomic_dec(&cache_resolve_queue_len); 303 atomic_dec(&cache_resolve_queue_len);
304 304
305 while((skb=skb_dequeue(&c->mfc_un.unres.unresolved))) { 305 while ((skb=skb_dequeue(&c->mfc_un.unres.unresolved))) {
306 if (skb->nh.iph->version == 0) { 306 if (skb->nh.iph->version == 0) {
307 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); 307 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
308 nlh->nlmsg_type = NLMSG_ERROR; 308 nlh->nlmsg_type = NLMSG_ERROR;
@@ -479,7 +479,7 @@ static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp)
479static struct mfc_cache *ipmr_cache_alloc(void) 479static struct mfc_cache *ipmr_cache_alloc(void)
480{ 480{
481 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); 481 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
482 if(c==NULL) 482 if (c==NULL)
483 return NULL; 483 return NULL;
484 c->mfc_un.res.minvif = MAXVIFS; 484 c->mfc_un.res.minvif = MAXVIFS;
485 return c; 485 return c;
@@ -488,7 +488,7 @@ static struct mfc_cache *ipmr_cache_alloc(void)
488static struct mfc_cache *ipmr_cache_alloc_unres(void) 488static struct mfc_cache *ipmr_cache_alloc_unres(void)
489{ 489{
490 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); 490 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
491 if(c==NULL) 491 if (c==NULL)
492 return NULL; 492 return NULL;
493 skb_queue_head_init(&c->mfc_un.unres.unresolved); 493 skb_queue_head_init(&c->mfc_un.unres.unresolved);
494 c->mfc_un.unres.expires = jiffies + 10*HZ; 494 c->mfc_un.unres.expires = jiffies + 10*HZ;
@@ -508,7 +508,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
508 * Play the pending entries through our router 508 * Play the pending entries through our router
509 */ 509 */
510 510
511 while((skb=__skb_dequeue(&uc->mfc_un.unres.unresolved))) { 511 while ((skb=__skb_dequeue(&uc->mfc_un.unres.unresolved))) {
512 if (skb->nh.iph->version == 0) { 512 if (skb->nh.iph->version == 0) {
513 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); 513 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
514 514
@@ -551,7 +551,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
551#endif 551#endif
552 skb = alloc_skb(128, GFP_ATOMIC); 552 skb = alloc_skb(128, GFP_ATOMIC);
553 553
554 if(!skb) 554 if (!skb)
555 return -ENOBUFS; 555 return -ENOBUFS;
556 556
557#ifdef CONFIG_IP_PIMSM 557#ifdef CONFIG_IP_PIMSM
@@ -734,7 +734,7 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
734 return 0; 734 return 0;
735 } 735 }
736 736
737 if(!MULTICAST(mfc->mfcc_mcastgrp.s_addr)) 737 if (!MULTICAST(mfc->mfcc_mcastgrp.s_addr))
738 return -EINVAL; 738 return -EINVAL;
739 739
740 c=ipmr_cache_alloc(); 740 c=ipmr_cache_alloc();
@@ -788,7 +788,7 @@ static void mroute_clean_tables(struct sock *sk)
788 /* 788 /*
789 * Shut down all active vif entries 789 * Shut down all active vif entries
790 */ 790 */
791 for(i=0; i<maxvif; i++) { 791 for (i=0; i<maxvif; i++) {
792 if (!(vif_table[i].flags&VIFF_STATIC)) 792 if (!(vif_table[i].flags&VIFF_STATIC))
793 vif_delete(i); 793 vif_delete(i);
794 } 794 }
@@ -858,119 +858,117 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
858 struct vifctl vif; 858 struct vifctl vif;
859 struct mfcctl mfc; 859 struct mfcctl mfc;
860 860
861 if(optname!=MRT_INIT) 861 if (optname != MRT_INIT) {
862 { 862 if (sk != mroute_socket && !capable(CAP_NET_ADMIN))
863 if(sk!=mroute_socket && !capable(CAP_NET_ADMIN))
864 return -EACCES; 863 return -EACCES;
865 } 864 }
866 865
867 switch(optname) 866 switch (optname) {
868 { 867 case MRT_INIT:
869 case MRT_INIT: 868 if (sk->sk_type != SOCK_RAW ||
870 if (sk->sk_type != SOCK_RAW || 869 inet_sk(sk)->num != IPPROTO_IGMP)
871 inet_sk(sk)->num != IPPROTO_IGMP) 870 return -EOPNOTSUPP;
872 return -EOPNOTSUPP; 871 if (optlen!=sizeof(int))
873 if(optlen!=sizeof(int)) 872 return -ENOPROTOOPT;
874 return -ENOPROTOOPT;
875
876 rtnl_lock();
877 if (mroute_socket) {
878 rtnl_unlock();
879 return -EADDRINUSE;
880 }
881
882 ret = ip_ra_control(sk, 1, mrtsock_destruct);
883 if (ret == 0) {
884 write_lock_bh(&mrt_lock);
885 mroute_socket=sk;
886 write_unlock_bh(&mrt_lock);
887 873
888 ipv4_devconf.mc_forwarding++; 874 rtnl_lock();
889 } 875 if (mroute_socket) {
890 rtnl_unlock(); 876 rtnl_unlock();
891 return ret; 877 return -EADDRINUSE;
892 case MRT_DONE: 878 }
893 if (sk!=mroute_socket) 879
894 return -EACCES; 880 ret = ip_ra_control(sk, 1, mrtsock_destruct);
895 return ip_ra_control(sk, 0, NULL); 881 if (ret == 0) {
896 case MRT_ADD_VIF: 882 write_lock_bh(&mrt_lock);
897 case MRT_DEL_VIF: 883 mroute_socket=sk;
898 if(optlen!=sizeof(vif)) 884 write_unlock_bh(&mrt_lock);
899 return -EINVAL; 885
900 if (copy_from_user(&vif,optval,sizeof(vif))) 886 ipv4_devconf.mc_forwarding++;
901 return -EFAULT; 887 }
902 if(vif.vifc_vifi >= MAXVIFS) 888 rtnl_unlock();
903 return -ENFILE; 889 return ret;
904 rtnl_lock(); 890 case MRT_DONE:
905 if (optname==MRT_ADD_VIF) { 891 if (sk!=mroute_socket)
906 ret = vif_add(&vif, sk==mroute_socket); 892 return -EACCES;
907 } else { 893 return ip_ra_control(sk, 0, NULL);
908 ret = vif_delete(vif.vifc_vifi); 894 case MRT_ADD_VIF:
909 } 895 case MRT_DEL_VIF:
910 rtnl_unlock(); 896 if (optlen!=sizeof(vif))
911 return ret; 897 return -EINVAL;
898 if (copy_from_user(&vif,optval,sizeof(vif)))
899 return -EFAULT;
900 if (vif.vifc_vifi >= MAXVIFS)
901 return -ENFILE;
902 rtnl_lock();
903 if (optname==MRT_ADD_VIF) {
904 ret = vif_add(&vif, sk==mroute_socket);
905 } else {
906 ret = vif_delete(vif.vifc_vifi);
907 }
908 rtnl_unlock();
909 return ret;
912 910
913 /* 911 /*
914 * Manipulate the forwarding caches. These live 912 * Manipulate the forwarding caches. These live
915 * in a sort of kernel/user symbiosis. 913 * in a sort of kernel/user symbiosis.
916 */ 914 */
917 case MRT_ADD_MFC: 915 case MRT_ADD_MFC:
918 case MRT_DEL_MFC: 916 case MRT_DEL_MFC:
919 if(optlen!=sizeof(mfc)) 917 if (optlen!=sizeof(mfc))
920 return -EINVAL; 918 return -EINVAL;
921 if (copy_from_user(&mfc,optval, sizeof(mfc))) 919 if (copy_from_user(&mfc,optval, sizeof(mfc)))
922 return -EFAULT; 920 return -EFAULT;
923 rtnl_lock(); 921 rtnl_lock();
924 if (optname==MRT_DEL_MFC) 922 if (optname==MRT_DEL_MFC)
925 ret = ipmr_mfc_delete(&mfc); 923 ret = ipmr_mfc_delete(&mfc);
926 else 924 else
927 ret = ipmr_mfc_add(&mfc, sk==mroute_socket); 925 ret = ipmr_mfc_add(&mfc, sk==mroute_socket);
928 rtnl_unlock(); 926 rtnl_unlock();
929 return ret; 927 return ret;
930 /* 928 /*
931 * Control PIM assert. 929 * Control PIM assert.
932 */ 930 */
933 case MRT_ASSERT: 931 case MRT_ASSERT:
934 { 932 {
935 int v; 933 int v;
936 if(get_user(v,(int __user *)optval)) 934 if (get_user(v,(int __user *)optval))
937 return -EFAULT; 935 return -EFAULT;
938 mroute_do_assert=(v)?1:0; 936 mroute_do_assert=(v)?1:0;
939 return 0; 937 return 0;
940 } 938 }
941#ifdef CONFIG_IP_PIMSM 939#ifdef CONFIG_IP_PIMSM
942 case MRT_PIM: 940 case MRT_PIM:
943 { 941 {
944 int v, ret; 942 int v, ret;
945 if(get_user(v,(int __user *)optval)) 943 if (get_user(v,(int __user *)optval))
946 return -EFAULT; 944 return -EFAULT;
947 v = (v)?1:0; 945 v = (v)?1:0;
948 rtnl_lock(); 946 rtnl_lock();
949 ret = 0; 947 ret = 0;
950 if (v != mroute_do_pim) { 948 if (v != mroute_do_pim) {
951 mroute_do_pim = v; 949 mroute_do_pim = v;
952 mroute_do_assert = v; 950 mroute_do_assert = v;
953#ifdef CONFIG_IP_PIMSM_V2 951#ifdef CONFIG_IP_PIMSM_V2
954 if (mroute_do_pim) 952 if (mroute_do_pim)
955 ret = inet_add_protocol(&pim_protocol, 953 ret = inet_add_protocol(&pim_protocol,
956 IPPROTO_PIM); 954 IPPROTO_PIM);
957 else 955 else
958 ret = inet_del_protocol(&pim_protocol, 956 ret = inet_del_protocol(&pim_protocol,
959 IPPROTO_PIM); 957 IPPROTO_PIM);
960 if (ret < 0) 958 if (ret < 0)
961 ret = -EAGAIN; 959 ret = -EAGAIN;
962#endif 960#endif
963 }
964 rtnl_unlock();
965 return ret;
966 } 961 }
962 rtnl_unlock();
963 return ret;
964 }
967#endif 965#endif
968 /* 966 /*
969 * Spurious command, or MRT_VERSION which you cannot 967 * Spurious command, or MRT_VERSION which you cannot
970 * set. 968 * set.
971 */ 969 */
972 default: 970 default:
973 return -ENOPROTOOPT; 971 return -ENOPROTOOPT;
974 } 972 }
975} 973}
976 974
@@ -983,7 +981,7 @@ int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __u
983 int olr; 981 int olr;
984 int val; 982 int val;
985 983
986 if(optname!=MRT_VERSION && 984 if (optname!=MRT_VERSION &&
987#ifdef CONFIG_IP_PIMSM 985#ifdef CONFIG_IP_PIMSM
988 optname!=MRT_PIM && 986 optname!=MRT_PIM &&
989#endif 987#endif
@@ -997,17 +995,17 @@ int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __u
997 if (olr < 0) 995 if (olr < 0)
998 return -EINVAL; 996 return -EINVAL;
999 997
1000 if(put_user(olr,optlen)) 998 if (put_user(olr,optlen))
1001 return -EFAULT; 999 return -EFAULT;
1002 if(optname==MRT_VERSION) 1000 if (optname==MRT_VERSION)
1003 val=0x0305; 1001 val=0x0305;
1004#ifdef CONFIG_IP_PIMSM 1002#ifdef CONFIG_IP_PIMSM
1005 else if(optname==MRT_PIM) 1003 else if (optname==MRT_PIM)
1006 val=mroute_do_pim; 1004 val=mroute_do_pim;
1007#endif 1005#endif
1008 else 1006 else
1009 val=mroute_do_assert; 1007 val=mroute_do_assert;
1010 if(copy_to_user(optval,&val,olr)) 1008 if (copy_to_user(optval,&val,olr))
1011 return -EFAULT; 1009 return -EFAULT;
1012 return 0; 1010 return 0;
1013} 1011}
@@ -1023,48 +1021,47 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1023 struct vif_device *vif; 1021 struct vif_device *vif;
1024 struct mfc_cache *c; 1022 struct mfc_cache *c;
1025 1023
1026 switch(cmd) 1024 switch (cmd) {
1027 { 1025 case SIOCGETVIFCNT:
1028 case SIOCGETVIFCNT: 1026 if (copy_from_user(&vr,arg,sizeof(vr)))
1029 if (copy_from_user(&vr,arg,sizeof(vr))) 1027 return -EFAULT;
1030 return -EFAULT; 1028 if (vr.vifi>=maxvif)
1031 if(vr.vifi>=maxvif) 1029 return -EINVAL;
1032 return -EINVAL; 1030 read_lock(&mrt_lock);
1033 read_lock(&mrt_lock); 1031 vif=&vif_table[vr.vifi];
1034 vif=&vif_table[vr.vifi]; 1032 if (VIF_EXISTS(vr.vifi)) {
1035 if(VIF_EXISTS(vr.vifi)) { 1033 vr.icount=vif->pkt_in;
1036 vr.icount=vif->pkt_in; 1034 vr.ocount=vif->pkt_out;
1037 vr.ocount=vif->pkt_out; 1035 vr.ibytes=vif->bytes_in;
1038 vr.ibytes=vif->bytes_in; 1036 vr.obytes=vif->bytes_out;
1039 vr.obytes=vif->bytes_out;
1040 read_unlock(&mrt_lock);
1041
1042 if (copy_to_user(arg,&vr,sizeof(vr)))
1043 return -EFAULT;
1044 return 0;
1045 }
1046 read_unlock(&mrt_lock); 1037 read_unlock(&mrt_lock);
1047 return -EADDRNOTAVAIL;
1048 case SIOCGETSGCNT:
1049 if (copy_from_user(&sr,arg,sizeof(sr)))
1050 return -EFAULT;
1051 1038
1052 read_lock(&mrt_lock); 1039 if (copy_to_user(arg,&vr,sizeof(vr)))
1053 c = ipmr_cache_find(sr.src.s_addr, sr.grp.s_addr); 1040 return -EFAULT;
1054 if (c) { 1041 return 0;
1055 sr.pktcnt = c->mfc_un.res.pkt; 1042 }
1056 sr.bytecnt = c->mfc_un.res.bytes; 1043 read_unlock(&mrt_lock);
1057 sr.wrong_if = c->mfc_un.res.wrong_if; 1044 return -EADDRNOTAVAIL;
1058 read_unlock(&mrt_lock); 1045 case SIOCGETSGCNT:
1059 1046 if (copy_from_user(&sr,arg,sizeof(sr)))
1060 if (copy_to_user(arg,&sr,sizeof(sr))) 1047 return -EFAULT;
1061 return -EFAULT; 1048
1062 return 0; 1049 read_lock(&mrt_lock);
1063 } 1050 c = ipmr_cache_find(sr.src.s_addr, sr.grp.s_addr);
1051 if (c) {
1052 sr.pktcnt = c->mfc_un.res.pkt;
1053 sr.bytecnt = c->mfc_un.res.bytes;
1054 sr.wrong_if = c->mfc_un.res.wrong_if;
1064 read_unlock(&mrt_lock); 1055 read_unlock(&mrt_lock);
1065 return -EADDRNOTAVAIL; 1056
1066 default: 1057 if (copy_to_user(arg,&sr,sizeof(sr)))
1067 return -ENOIOCTLCMD; 1058 return -EFAULT;
1059 return 0;
1060 }
1061 read_unlock(&mrt_lock);
1062 return -EADDRNOTAVAIL;
1063 default:
1064 return -ENOIOCTLCMD;
1068 } 1065 }
1069} 1066}
1070 1067
@@ -1076,7 +1073,7 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v
1076 if (event != NETDEV_UNREGISTER) 1073 if (event != NETDEV_UNREGISTER)
1077 return NOTIFY_DONE; 1074 return NOTIFY_DONE;
1078 v=&vif_table[0]; 1075 v=&vif_table[0];
1079 for(ct=0;ct<maxvif;ct++,v++) { 1076 for (ct=0;ct<maxvif;ct++,v++) {
1080 if (v->dev==ptr) 1077 if (v->dev==ptr)
1081 vif_delete(ct); 1078 vif_delete(ct);
1082 } 1079 }
@@ -1625,7 +1622,7 @@ static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter,
1625 loff_t pos) 1622 loff_t pos)
1626{ 1623{
1627 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) { 1624 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) {
1628 if(!VIF_EXISTS(iter->ct)) 1625 if (!VIF_EXISTS(iter->ct))
1629 continue; 1626 continue;
1630 if (pos-- == 0) 1627 if (pos-- == 0)
1631 return &vif_table[iter->ct]; 1628 return &vif_table[iter->ct];
@@ -1649,7 +1646,7 @@ static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1649 return ipmr_vif_seq_idx(iter, 0); 1646 return ipmr_vif_seq_idx(iter, 0);
1650 1647
1651 while (++iter->ct < maxvif) { 1648 while (++iter->ct < maxvif) {
1652 if(!VIF_EXISTS(iter->ct)) 1649 if (!VIF_EXISTS(iter->ct))
1653 continue; 1650 continue;
1654 return &vif_table[iter->ct]; 1651 return &vif_table[iter->ct];
1655 } 1652 }
@@ -1732,14 +1729,14 @@ static struct mfc_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
1732 it->cache = mfc_cache_array; 1729 it->cache = mfc_cache_array;
1733 read_lock(&mrt_lock); 1730 read_lock(&mrt_lock);
1734 for (it->ct = 0; it->ct < MFC_LINES; it->ct++) 1731 for (it->ct = 0; it->ct < MFC_LINES; it->ct++)
1735 for(mfc = mfc_cache_array[it->ct]; mfc; mfc = mfc->next) 1732 for (mfc = mfc_cache_array[it->ct]; mfc; mfc = mfc->next)
1736 if (pos-- == 0) 1733 if (pos-- == 0)
1737 return mfc; 1734 return mfc;
1738 read_unlock(&mrt_lock); 1735 read_unlock(&mrt_lock);
1739 1736
1740 it->cache = &mfc_unres_queue; 1737 it->cache = &mfc_unres_queue;
1741 spin_lock_bh(&mfc_unres_lock); 1738 spin_lock_bh(&mfc_unres_lock);
1742 for(mfc = mfc_unres_queue; mfc; mfc = mfc->next) 1739 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next)
1743 if (pos-- == 0) 1740 if (pos-- == 0)
1744 return mfc; 1741 return mfc;
1745 spin_unlock_bh(&mfc_unres_lock); 1742 spin_unlock_bh(&mfc_unres_lock);
@@ -1829,9 +1826,9 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1829 mfc->mfc_un.res.wrong_if); 1826 mfc->mfc_un.res.wrong_if);
1830 1827
1831 if (it->cache != &mfc_unres_queue) { 1828 if (it->cache != &mfc_unres_queue) {
1832 for(n = mfc->mfc_un.res.minvif; 1829 for (n = mfc->mfc_un.res.minvif;
1833 n < mfc->mfc_un.res.maxvif; n++ ) { 1830 n < mfc->mfc_un.res.maxvif; n++ ) {
1834 if(VIF_EXISTS(n) 1831 if (VIF_EXISTS(n)
1835 && mfc->mfc_un.res.ttls[n] < 255) 1832 && mfc->mfc_un.res.ttls[n] < 255)
1836 seq_printf(seq, 1833 seq_printf(seq,
1837 " %2d:%-3d", 1834 " %2d:%-3d",
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c
index ceb4376f572a..4872b30ba5d8 100644
--- a/net/ipv4/xfrm4_mode_tunnel.c
+++ b/net/ipv4/xfrm4_mode_tunnel.c
@@ -93,7 +93,7 @@ static int xfrm4_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
93 struct iphdr *iph = skb->nh.iph; 93 struct iphdr *iph = skb->nh.iph;
94 int err = -EINVAL; 94 int err = -EINVAL;
95 95
96 switch(iph->protocol){ 96 switch (iph->protocol){
97 case IPPROTO_IPIP: 97 case IPPROTO_IPIP:
98 break; 98 break;
99#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 99#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 5d51a2af34c1..98a833ce1114 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -119,7 +119,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
119 119
120 if (xfrm[i]->props.mode == XFRM_MODE_TUNNEL) { 120 if (xfrm[i]->props.mode == XFRM_MODE_TUNNEL) {
121 unsigned short encap_family = xfrm[i]->props.family; 121 unsigned short encap_family = xfrm[i]->props.family;
122 switch(encap_family) { 122 switch (encap_family) {
123 case AF_INET: 123 case AF_INET:
124 fl_tunnel.fl4_dst = xfrm[i]->id.daddr.a4; 124 fl_tunnel.fl4_dst = xfrm[i]->id.daddr.a4;
125 fl_tunnel.fl4_src = xfrm[i]->props.saddr.a4; 125 fl_tunnel.fl4_src = xfrm[i]->props.saddr.a4;