aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/ipmr.c
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/ipmr.c
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/ipmr.c')
-rw-r--r--net/ipv4/ipmr.c305
1 files changed, 151 insertions, 154 deletions
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",