aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/route.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/route.c')
-rw-r--r--net/ipv4/route.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 36c7add8de84..1cc6c23cf758 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1154,7 +1154,8 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1154 return; 1154 return;
1155 1155
1156 if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev) 1156 if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev)
1157 || MULTICAST(new_gw) || BADCLASS(new_gw) || ZERONET(new_gw)) 1157 || ipv4_is_multicast(new_gw) || ipv4_is_badclass(new_gw)
1158 || ipv4_is_zeronet(new_gw))
1158 goto reject_redirect; 1159 goto reject_redirect;
1159 1160
1160 if (!IN_DEV_SHARED_MEDIA(in_dev)) { 1161 if (!IN_DEV_SHARED_MEDIA(in_dev)) {
@@ -1633,12 +1634,12 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1633 if (in_dev == NULL) 1634 if (in_dev == NULL)
1634 return -EINVAL; 1635 return -EINVAL;
1635 1636
1636 if (MULTICAST(saddr) || BADCLASS(saddr) || LOOPBACK(saddr) || 1637 if (ipv4_is_multicast(saddr) || ipv4_is_badclass(saddr) ||
1637 skb->protocol != htons(ETH_P_IP)) 1638 ipv4_is_loopback(saddr) || skb->protocol != htons(ETH_P_IP))
1638 goto e_inval; 1639 goto e_inval;
1639 1640
1640 if (ZERONET(saddr)) { 1641 if (ipv4_is_zeronet(saddr)) {
1641 if (!LOCAL_MCAST(daddr)) 1642 if (!ipv4_is_local_multicast(daddr))
1642 goto e_inval; 1643 goto e_inval;
1643 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK); 1644 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
1644 } else if (fib_validate_source(saddr, 0, tos, 0, 1645 } else if (fib_validate_source(saddr, 0, tos, 0,
@@ -1680,7 +1681,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1680 } 1681 }
1681 1682
1682#ifdef CONFIG_IP_MROUTE 1683#ifdef CONFIG_IP_MROUTE
1683 if (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev)) 1684 if (!ipv4_is_local_multicast(daddr) && IN_DEV_MFORWARD(in_dev))
1684 rth->u.dst.input = ip_mr_input; 1685 rth->u.dst.input = ip_mr_input;
1685#endif 1686#endif
1686 RT_CACHE_STAT_INC(in_slow_mc); 1687 RT_CACHE_STAT_INC(in_slow_mc);
@@ -1890,7 +1891,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1890 by fib_lookup. 1891 by fib_lookup.
1891 */ 1892 */
1892 1893
1893 if (MULTICAST(saddr) || BADCLASS(saddr) || LOOPBACK(saddr)) 1894 if (ipv4_is_multicast(saddr) || ipv4_is_badclass(saddr) ||
1895 ipv4_is_loopback(saddr))
1894 goto martian_source; 1896 goto martian_source;
1895 1897
1896 if (daddr == htonl(0xFFFFFFFF) || (saddr == 0 && daddr == 0)) 1898 if (daddr == htonl(0xFFFFFFFF) || (saddr == 0 && daddr == 0))
@@ -1899,10 +1901,11 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1899 /* Accept zero addresses only to limited broadcast; 1901 /* Accept zero addresses only to limited broadcast;
1900 * I even do not know to fix it or not. Waiting for complains :-) 1902 * I even do not know to fix it or not. Waiting for complains :-)
1901 */ 1903 */
1902 if (ZERONET(saddr)) 1904 if (ipv4_is_zeronet(saddr))
1903 goto martian_source; 1905 goto martian_source;
1904 1906
1905 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr)) 1907 if (ipv4_is_badclass(daddr) || ipv4_is_zeronet(daddr) ||
1908 ipv4_is_loopback(daddr))
1906 goto martian_destination; 1909 goto martian_destination;
1907 1910
1908 /* 1911 /*
@@ -1949,7 +1952,7 @@ brd_input:
1949 if (skb->protocol != htons(ETH_P_IP)) 1952 if (skb->protocol != htons(ETH_P_IP))
1950 goto e_inval; 1953 goto e_inval;
1951 1954
1952 if (ZERONET(saddr)) 1955 if (ipv4_is_zeronet(saddr))
1953 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK); 1956 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
1954 else { 1957 else {
1955 err = fib_validate_source(saddr, 0, tos, 0, dev, &spec_dst, 1958 err = fib_validate_source(saddr, 0, tos, 0, dev, &spec_dst,
@@ -2079,7 +2082,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2079 Note, that multicast routers are not affected, because 2082 Note, that multicast routers are not affected, because
2080 route cache entry is created eventually. 2083 route cache entry is created eventually.
2081 */ 2084 */
2082 if (MULTICAST(daddr)) { 2085 if (ipv4_is_multicast(daddr)) {
2083 struct in_device *in_dev; 2086 struct in_device *in_dev;
2084 2087
2085 rcu_read_lock(); 2088 rcu_read_lock();
@@ -2088,7 +2091,8 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2088 ip_hdr(skb)->protocol); 2091 ip_hdr(skb)->protocol);
2089 if (our 2092 if (our
2090#ifdef CONFIG_IP_MROUTE 2093#ifdef CONFIG_IP_MROUTE
2091 || (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev)) 2094 || (!ipv4_is_local_multicast(daddr) &&
2095 IN_DEV_MFORWARD(in_dev))
2092#endif 2096#endif
2093 ) { 2097 ) {
2094 rcu_read_unlock(); 2098 rcu_read_unlock();
@@ -2114,14 +2118,14 @@ static inline int __mkroute_output(struct rtable **result,
2114 u32 tos = RT_FL_TOS(oldflp); 2118 u32 tos = RT_FL_TOS(oldflp);
2115 int err = 0; 2119 int err = 0;
2116 2120
2117 if (LOOPBACK(fl->fl4_src) && !(dev_out->flags&IFF_LOOPBACK)) 2121 if (ipv4_is_loopback(fl->fl4_src) && !(dev_out->flags&IFF_LOOPBACK))
2118 return -EINVAL; 2122 return -EINVAL;
2119 2123
2120 if (fl->fl4_dst == htonl(0xFFFFFFFF)) 2124 if (fl->fl4_dst == htonl(0xFFFFFFFF))
2121 res->type = RTN_BROADCAST; 2125 res->type = RTN_BROADCAST;
2122 else if (MULTICAST(fl->fl4_dst)) 2126 else if (ipv4_is_multicast(fl->fl4_dst))
2123 res->type = RTN_MULTICAST; 2127 res->type = RTN_MULTICAST;
2124 else if (BADCLASS(fl->fl4_dst) || ZERONET(fl->fl4_dst)) 2128 else if (ipv4_is_badclass(fl->fl4_dst) || ipv4_is_zeronet(fl->fl4_dst))
2125 return -EINVAL; 2129 return -EINVAL;
2126 2130
2127 if (dev_out->flags & IFF_LOOPBACK) 2131 if (dev_out->flags & IFF_LOOPBACK)
@@ -2201,7 +2205,7 @@ static inline int __mkroute_output(struct rtable **result,
2201#ifdef CONFIG_IP_MROUTE 2205#ifdef CONFIG_IP_MROUTE
2202 if (res->type == RTN_MULTICAST) { 2206 if (res->type == RTN_MULTICAST) {
2203 if (IN_DEV_MFORWARD(in_dev) && 2207 if (IN_DEV_MFORWARD(in_dev) &&
2204 !LOCAL_MCAST(oldflp->fl4_dst)) { 2208 !ipv4_is_local_multicast(oldflp->fl4_dst)) {
2205 rth->u.dst.input = ip_mr_input; 2209 rth->u.dst.input = ip_mr_input;
2206 rth->u.dst.output = ip_mc_output; 2210 rth->u.dst.output = ip_mc_output;
2207 } 2211 }
@@ -2271,9 +2275,9 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
2271 2275
2272 if (oldflp->fl4_src) { 2276 if (oldflp->fl4_src) {
2273 err = -EINVAL; 2277 err = -EINVAL;
2274 if (MULTICAST(oldflp->fl4_src) || 2278 if (ipv4_is_multicast(oldflp->fl4_src) ||
2275 BADCLASS(oldflp->fl4_src) || 2279 ipv4_is_badclass(oldflp->fl4_src) ||
2276 ZERONET(oldflp->fl4_src)) 2280 ipv4_is_zeronet(oldflp->fl4_src))
2277 goto out; 2281 goto out;
2278 2282
2279 /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */ 2283 /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
@@ -2290,7 +2294,8 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
2290 */ 2294 */
2291 2295
2292 if (oldflp->oif == 0 2296 if (oldflp->oif == 0
2293 && (MULTICAST(oldflp->fl4_dst) || oldflp->fl4_dst == htonl(0xFFFFFFFF))) { 2297 && (ipv4_is_multicast(oldflp->fl4_dst) ||
2298 oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
2294 /* Special hack: user can direct multicasts 2299 /* Special hack: user can direct multicasts
2295 and limited broadcast via necessary interface 2300 and limited broadcast via necessary interface
2296 without fiddling with IP_MULTICAST_IF or IP_PKTINFO. 2301 without fiddling with IP_MULTICAST_IF or IP_PKTINFO.
@@ -2327,14 +2332,15 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
2327 goto out; /* Wrong error code */ 2332 goto out; /* Wrong error code */
2328 } 2333 }
2329 2334
2330 if (LOCAL_MCAST(oldflp->fl4_dst) || oldflp->fl4_dst == htonl(0xFFFFFFFF)) { 2335 if (ipv4_is_local_multicast(oldflp->fl4_dst) ||
2336 oldflp->fl4_dst == htonl(0xFFFFFFFF)) {
2331 if (!fl.fl4_src) 2337 if (!fl.fl4_src)
2332 fl.fl4_src = inet_select_addr(dev_out, 0, 2338 fl.fl4_src = inet_select_addr(dev_out, 0,
2333 RT_SCOPE_LINK); 2339 RT_SCOPE_LINK);
2334 goto make_route; 2340 goto make_route;
2335 } 2341 }
2336 if (!fl.fl4_src) { 2342 if (!fl.fl4_src) {
2337 if (MULTICAST(oldflp->fl4_dst)) 2343 if (ipv4_is_multicast(oldflp->fl4_dst))
2338 fl.fl4_src = inet_select_addr(dev_out, 0, 2344 fl.fl4_src = inet_select_addr(dev_out, 0,
2339 fl.fl4_scope); 2345 fl.fl4_scope);
2340 else if (!oldflp->fl4_dst) 2346 else if (!oldflp->fl4_dst)
@@ -2618,7 +2624,7 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
2618#ifdef CONFIG_IP_MROUTE 2624#ifdef CONFIG_IP_MROUTE
2619 __be32 dst = rt->rt_dst; 2625 __be32 dst = rt->rt_dst;
2620 2626
2621 if (MULTICAST(dst) && !LOCAL_MCAST(dst) && 2627 if (ipv4_is_multicast(dst) && !ipv4_is_local_multicast(dst) &&
2622 IPV4_DEVCONF_ALL(&init_net, MC_FORWARDING)) { 2628 IPV4_DEVCONF_ALL(&init_net, MC_FORWARDING)) {
2623 int err = ipmr_get_route(skb, r, nowait); 2629 int err = ipmr_get_route(skb, r, nowait);
2624 if (err <= 0) { 2630 if (err <= 0) {