aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/fib_frontend.c
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-10-04 16:00:18 -0400
committerDavid S. Miller <davem@davemloft.net>2010-10-05 03:47:38 -0400
commit6a31d2a97c04ffe9b161ec0177a2296366ff9249 (patch)
treee564d7b06a69927f572e629b9281682f3c5c6cee /net/ipv4/fib_frontend.c
parente3d32687a624845e97f9717d9d2027b44b8c49a2 (diff)
fib: cleanups
Code style cleanups before upcoming functional changes. C99 initializer for fib_props array. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/fib_frontend.c')
-rw-r--r--net/ipv4/fib_frontend.c121
1 files changed, 66 insertions, 55 deletions
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 4a69a957872b..b05c23b05a9f 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -225,30 +225,33 @@ EXPORT_SYMBOL(inet_addr_type);
225unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev, 225unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev,
226 __be32 addr) 226 __be32 addr)
227{ 227{
228 return __inet_dev_addr_type(net, dev, addr); 228 return __inet_dev_addr_type(net, dev, addr);
229} 229}
230EXPORT_SYMBOL(inet_dev_addr_type); 230EXPORT_SYMBOL(inet_dev_addr_type);
231 231
232/* Given (packet source, input interface) and optional (dst, oif, tos): 232/* Given (packet source, input interface) and optional (dst, oif, tos):
233 - (main) check, that source is valid i.e. not broadcast or our local 233 * - (main) check, that source is valid i.e. not broadcast or our local
234 address. 234 * address.
235 - figure out what "logical" interface this packet arrived 235 * - figure out what "logical" interface this packet arrived
236 and calculate "specific destination" address. 236 * and calculate "specific destination" address.
237 - check, that packet arrived from expected physical interface. 237 * - check, that packet arrived from expected physical interface.
238 */ 238 */
239
240int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, 239int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
241 struct net_device *dev, __be32 *spec_dst, 240 struct net_device *dev, __be32 *spec_dst,
242 u32 *itag, u32 mark) 241 u32 *itag, u32 mark)
243{ 242{
244 struct in_device *in_dev; 243 struct in_device *in_dev;
245 struct flowi fl = { .nl_u = { .ip4_u = 244 struct flowi fl = {
246 { .daddr = src, 245 .nl_u = {
247 .saddr = dst, 246 .ip4_u = {
248 .tos = tos } }, 247 .daddr = src,
249 .mark = mark, 248 .saddr = dst,
250 .iif = oif }; 249 .tos = tos
251 250 }
251 },
252 .mark = mark,
253 .iif = oif
254 };
252 struct fib_result res; 255 struct fib_result res;
253 int no_addr, rpf, accept_local; 256 int no_addr, rpf, accept_local;
254 bool dev_match; 257 bool dev_match;
@@ -477,9 +480,9 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
477} 480}
478 481
479/* 482/*
480 * Handle IP routing ioctl calls. These are used to manipulate the routing tables 483 * Handle IP routing ioctl calls.
484 * These are used to manipulate the routing tables
481 */ 485 */
482
483int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg) 486int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
484{ 487{
485 struct fib_config cfg; 488 struct fib_config cfg;
@@ -523,7 +526,7 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
523 return -EINVAL; 526 return -EINVAL;
524} 527}
525 528
526const struct nla_policy rtm_ipv4_policy[RTA_MAX+1] = { 529const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
527 [RTA_DST] = { .type = NLA_U32 }, 530 [RTA_DST] = { .type = NLA_U32 },
528 [RTA_SRC] = { .type = NLA_U32 }, 531 [RTA_SRC] = { .type = NLA_U32 },
529 [RTA_IIF] = { .type = NLA_U32 }, 532 [RTA_IIF] = { .type = NLA_U32 },
@@ -537,7 +540,7 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX+1] = {
537}; 540};
538 541
539static int rtm_to_fib_config(struct net *net, struct sk_buff *skb, 542static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
540 struct nlmsghdr *nlh, struct fib_config *cfg) 543 struct nlmsghdr *nlh, struct fib_config *cfg)
541{ 544{
542 struct nlattr *attr; 545 struct nlattr *attr;
543 int err, remaining; 546 int err, remaining;
@@ -692,12 +695,11 @@ out:
692} 695}
693 696
694/* Prepare and feed intra-kernel routing request. 697/* Prepare and feed intra-kernel routing request.
695 Really, it should be netlink message, but :-( netlink 698 * Really, it should be netlink message, but :-( netlink
696 can be not configured, so that we feed it directly 699 * can be not configured, so that we feed it directly
697 to fib engine. It is legal, because all events occur 700 * to fib engine. It is legal, because all events occur
698 only when netlink is already locked. 701 * only when netlink is already locked.
699 */ 702 */
700
701static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa) 703static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa)
702{ 704{
703 struct net *net = dev_net(ifa->ifa_dev->dev); 705 struct net *net = dev_net(ifa->ifa_dev->dev);
@@ -743,9 +745,9 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
743 struct in_ifaddr *prim = ifa; 745 struct in_ifaddr *prim = ifa;
744 __be32 mask = ifa->ifa_mask; 746 __be32 mask = ifa->ifa_mask;
745 __be32 addr = ifa->ifa_local; 747 __be32 addr = ifa->ifa_local;
746 __be32 prefix = ifa->ifa_address&mask; 748 __be32 prefix = ifa->ifa_address & mask;
747 749
748 if (ifa->ifa_flags&IFA_F_SECONDARY) { 750 if (ifa->ifa_flags & IFA_F_SECONDARY) {
749 prim = inet_ifa_byprefix(in_dev, prefix, mask); 751 prim = inet_ifa_byprefix(in_dev, prefix, mask);
750 if (prim == NULL) { 752 if (prim == NULL) {
751 printk(KERN_WARNING "fib_add_ifaddr: bug: prim == NULL\n"); 753 printk(KERN_WARNING "fib_add_ifaddr: bug: prim == NULL\n");
@@ -755,22 +757,24 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
755 757
756 fib_magic(RTM_NEWROUTE, RTN_LOCAL, addr, 32, prim); 758 fib_magic(RTM_NEWROUTE, RTN_LOCAL, addr, 32, prim);
757 759
758 if (!(dev->flags&IFF_UP)) 760 if (!(dev->flags & IFF_UP))
759 return; 761 return;
760 762
761 /* Add broadcast address, if it is explicitly assigned. */ 763 /* Add broadcast address, if it is explicitly assigned. */
762 if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF)) 764 if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
763 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim); 765 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
764 766
765 if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags&IFA_F_SECONDARY) && 767 if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
766 (prefix != addr || ifa->ifa_prefixlen < 32)) { 768 (prefix != addr || ifa->ifa_prefixlen < 32)) {
767 fib_magic(RTM_NEWROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL : 769 fib_magic(RTM_NEWROUTE,
768 RTN_UNICAST, prefix, ifa->ifa_prefixlen, prim); 770 dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
771 prefix, ifa->ifa_prefixlen, prim);
769 772
770 /* Add network specific broadcasts, when it takes a sense */ 773 /* Add network specific broadcasts, when it takes a sense */
771 if (ifa->ifa_prefixlen < 31) { 774 if (ifa->ifa_prefixlen < 31) {
772 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32, prim); 775 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32, prim);
773 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix|~mask, 32, prim); 776 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask,
777 32, prim);
774 } 778 }
775 } 779 }
776} 780}
@@ -781,17 +785,18 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
781 struct net_device *dev = in_dev->dev; 785 struct net_device *dev = in_dev->dev;
782 struct in_ifaddr *ifa1; 786 struct in_ifaddr *ifa1;
783 struct in_ifaddr *prim = ifa; 787 struct in_ifaddr *prim = ifa;
784 __be32 brd = ifa->ifa_address|~ifa->ifa_mask; 788 __be32 brd = ifa->ifa_address | ~ifa->ifa_mask;
785 __be32 any = ifa->ifa_address&ifa->ifa_mask; 789 __be32 any = ifa->ifa_address & ifa->ifa_mask;
786#define LOCAL_OK 1 790#define LOCAL_OK 1
787#define BRD_OK 2 791#define BRD_OK 2
788#define BRD0_OK 4 792#define BRD0_OK 4
789#define BRD1_OK 8 793#define BRD1_OK 8
790 unsigned ok = 0; 794 unsigned ok = 0;
791 795
792 if (!(ifa->ifa_flags&IFA_F_SECONDARY)) 796 if (!(ifa->ifa_flags & IFA_F_SECONDARY))
793 fib_magic(RTM_DELROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL : 797 fib_magic(RTM_DELROUTE,
794 RTN_UNICAST, any, ifa->ifa_prefixlen, prim); 798 dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
799 any, ifa->ifa_prefixlen, prim);
795 else { 800 else {
796 prim = inet_ifa_byprefix(in_dev, any, ifa->ifa_mask); 801 prim = inet_ifa_byprefix(in_dev, any, ifa->ifa_mask);
797 if (prim == NULL) { 802 if (prim == NULL) {
@@ -801,9 +806,9 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
801 } 806 }
802 807
803 /* Deletion is more complicated than add. 808 /* Deletion is more complicated than add.
804 We should take care of not to delete too much :-) 809 * We should take care of not to delete too much :-)
805 810 *
806 Scan address list to be sure that addresses are really gone. 811 * Scan address list to be sure that addresses are really gone.
807 */ 812 */
808 813
809 for (ifa1 = in_dev->ifa_list; ifa1; ifa1 = ifa1->ifa_next) { 814 for (ifa1 = in_dev->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
@@ -817,23 +822,23 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
817 ok |= BRD0_OK; 822 ok |= BRD0_OK;
818 } 823 }
819 824
820 if (!(ok&BRD_OK)) 825 if (!(ok & BRD_OK))
821 fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim); 826 fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
822 if (!(ok&BRD1_OK)) 827 if (!(ok & BRD1_OK))
823 fib_magic(RTM_DELROUTE, RTN_BROADCAST, brd, 32, prim); 828 fib_magic(RTM_DELROUTE, RTN_BROADCAST, brd, 32, prim);
824 if (!(ok&BRD0_OK)) 829 if (!(ok & BRD0_OK))
825 fib_magic(RTM_DELROUTE, RTN_BROADCAST, any, 32, prim); 830 fib_magic(RTM_DELROUTE, RTN_BROADCAST, any, 32, prim);
826 if (!(ok&LOCAL_OK)) { 831 if (!(ok & LOCAL_OK)) {
827 fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 32, prim); 832 fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 32, prim);
828 833
829 /* Check, that this local address finally disappeared. */ 834 /* Check, that this local address finally disappeared. */
830 if (inet_addr_type(dev_net(dev), ifa->ifa_local) != RTN_LOCAL) { 835 if (inet_addr_type(dev_net(dev), ifa->ifa_local) != RTN_LOCAL) {
831 /* And the last, but not the least thing. 836 /* And the last, but not the least thing.
832 We must flush stray FIB entries. 837 * We must flush stray FIB entries.
833 838 *
834 First of all, we scan fib_info list searching 839 * First of all, we scan fib_info list searching
835 for stray nexthop entries, then ignite fib_flush. 840 * for stray nexthop entries, then ignite fib_flush.
836 */ 841 */
837 if (fib_sync_down_addr(dev_net(dev), ifa->ifa_local)) 842 if (fib_sync_down_addr(dev_net(dev), ifa->ifa_local))
838 fib_flush(dev_net(dev)); 843 fib_flush(dev_net(dev));
839 } 844 }
@@ -844,14 +849,20 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
844#undef BRD1_OK 849#undef BRD1_OK
845} 850}
846 851
847static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb ) 852static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb)
848{ 853{
849 854
850 struct fib_result res; 855 struct fib_result res;
851 struct flowi fl = { .mark = frn->fl_mark, 856 struct flowi fl = {
852 .nl_u = { .ip4_u = { .daddr = frn->fl_addr, 857 .mark = frn->fl_mark,
853 .tos = frn->fl_tos, 858 .nl_u = {
854 .scope = frn->fl_scope } } }; 859 .ip4_u = {
860 .daddr = frn->fl_addr,
861 .tos = frn->fl_tos,
862 .scope = frn->fl_scope
863 }
864 }
865 };
855 866
856#ifdef CONFIG_IP_MULTIPLE_TABLES 867#ifdef CONFIG_IP_MULTIPLE_TABLES
857 res.r = NULL; 868 res.r = NULL;
@@ -899,8 +910,8 @@ static void nl_fib_input(struct sk_buff *skb)
899 910
900 nl_fib_lookup(frn, tb); 911 nl_fib_lookup(frn, tb);
901 912
902 pid = NETLINK_CB(skb).pid; /* pid of sending process */ 913 pid = NETLINK_CB(skb).pid; /* pid of sending process */
903 NETLINK_CB(skb).pid = 0; /* from kernel */ 914 NETLINK_CB(skb).pid = 0; /* from kernel */
904 NETLINK_CB(skb).dst_group = 0; /* unicast */ 915 NETLINK_CB(skb).dst_group = 0; /* unicast */
905 netlink_unicast(net->ipv4.fibnl, skb, pid, MSG_DONTWAIT); 916 netlink_unicast(net->ipv4.fibnl, skb, pid, MSG_DONTWAIT);
906} 917}
@@ -947,7 +958,7 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
947 fib_del_ifaddr(ifa); 958 fib_del_ifaddr(ifa);
948 if (ifa->ifa_dev->ifa_list == NULL) { 959 if (ifa->ifa_dev->ifa_list == NULL) {
949 /* Last address was deleted from this interface. 960 /* Last address was deleted from this interface.
950 Disable IP. 961 * Disable IP.
951 */ 962 */
952 fib_disable_ip(dev, 1, 0); 963 fib_disable_ip(dev, 1, 0);
953 } else { 964 } else {