Commit 38308473 authored by David S. Miller's avatar David S. Miller

ipv6: Various cleanups in route.c

1) x == NULL --> !x
2) x != NULL --> x
3) (x&BIT) --> (x & BIT)
4) (BIT1|BIT2) --> (BIT1 | BIT2)
5) proper argument and struct member alignment
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 507c9b1e
...@@ -247,9 +247,9 @@ static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops, ...@@ -247,9 +247,9 @@ static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops,
{ {
struct rt6_info *rt = dst_alloc(ops, dev, 0, 0, flags); struct rt6_info *rt = dst_alloc(ops, dev, 0, 0, flags);
if (rt != NULL) if (rt)
memset(&rt->rt6i_table, 0, memset(&rt->rt6i_table, 0,
sizeof(*rt) - sizeof(struct dst_entry)); sizeof(*rt) - sizeof(struct dst_entry));
return rt; return rt;
} }
...@@ -263,7 +263,7 @@ static void ip6_dst_destroy(struct dst_entry *dst) ...@@ -263,7 +263,7 @@ static void ip6_dst_destroy(struct dst_entry *dst)
if (!(rt->dst.flags & DST_HOST)) if (!(rt->dst.flags & DST_HOST))
dst_destroy_metrics_generic(dst); dst_destroy_metrics_generic(dst);
if (idev != NULL) { if (idev) {
rt->rt6i_idev = NULL; rt->rt6i_idev = NULL;
in6_dev_put(idev); in6_dev_put(idev);
} }
...@@ -299,10 +299,10 @@ static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev, ...@@ -299,10 +299,10 @@ static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
struct net_device *loopback_dev = struct net_device *loopback_dev =
dev_net(dev)->loopback_dev; dev_net(dev)->loopback_dev;
if (dev != loopback_dev && idev != NULL && idev->dev == dev) { if (dev != loopback_dev && idev && idev->dev == dev) {
struct inet6_dev *loopback_idev = struct inet6_dev *loopback_idev =
in6_dev_get(loopback_dev); in6_dev_get(loopback_dev);
if (loopback_idev != NULL) { if (loopback_idev) {
rt->rt6i_idev = loopback_idev; rt->rt6i_idev = loopback_idev;
in6_dev_put(idev); in6_dev_put(idev);
} }
...@@ -344,7 +344,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net, ...@@ -344,7 +344,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net,
if (dev->ifindex == oif) if (dev->ifindex == oif)
return sprt; return sprt;
if (dev->flags & IFF_LOOPBACK) { if (dev->flags & IFF_LOOPBACK) {
if (sprt->rt6i_idev == NULL || if (!sprt->rt6i_idev ||
sprt->rt6i_idev->dev->ifindex != oif) { sprt->rt6i_idev->dev->ifindex != oif) {
if (flags & RT6_LOOKUP_F_IFACE && oif) if (flags & RT6_LOOKUP_F_IFACE && oif)
continue; continue;
...@@ -636,7 +636,7 @@ do { \ ...@@ -636,7 +636,7 @@ do { \
goto restart; \ goto restart; \
} \ } \
} \ } \
} while(0) } while (0)
static struct rt6_info *ip6_pol_route_lookup(struct net *net, static struct rt6_info *ip6_pol_route_lookup(struct net *net,
struct fib6_table *table, struct fib6_table *table,
...@@ -727,7 +727,7 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort, ...@@ -727,7 +727,7 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
struct neighbour *neigh; struct neighbour *neigh;
int attempts = !in_softirq(); int attempts = !in_softirq();
if (!(rt->rt6i_flags&RTF_GATEWAY)) { if (!(rt->rt6i_flags & RTF_GATEWAY)) {
if (rt->rt6i_dst.plen != 128 && if (rt->rt6i_dst.plen != 128 &&
ipv6_addr_equal(&ort->rt6i_dst.addr, daddr)) ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
rt->rt6i_flags |= RTF_ANYCAST; rt->rt6i_flags |= RTF_ANYCAST;
...@@ -875,7 +875,7 @@ void ip6_route_input(struct sk_buff *skb) ...@@ -875,7 +875,7 @@ void ip6_route_input(struct sk_buff *skb)
.flowi6_iif = skb->dev->ifindex, .flowi6_iif = skb->dev->ifindex,
.daddr = iph->daddr, .daddr = iph->daddr,
.saddr = iph->saddr, .saddr = iph->saddr,
.flowlabel = (* (__be32 *) iph)&IPV6_FLOWINFO_MASK, .flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
.flowi6_mark = skb->mark, .flowi6_mark = skb->mark,
.flowi6_proto = iph->nexthdr, .flowi6_proto = iph->nexthdr,
}; };
...@@ -997,7 +997,7 @@ static void ip6_link_failure(struct sk_buff *skb) ...@@ -997,7 +997,7 @@ static void ip6_link_failure(struct sk_buff *skb)
rt = (struct rt6_info *) skb_dst(skb); rt = (struct rt6_info *) skb_dst(skb);
if (rt) { if (rt) {
if (rt->rt6i_flags&RTF_CACHE) { if (rt->rt6i_flags & RTF_CACHE) {
dst_set_expires(&rt->dst, 0); dst_set_expires(&rt->dst, 0);
rt->rt6i_flags |= RTF_EXPIRES; rt->rt6i_flags |= RTF_EXPIRES;
} else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT)) } else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT))
...@@ -1073,11 +1073,11 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev, ...@@ -1073,11 +1073,11 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
struct inet6_dev *idev = in6_dev_get(dev); struct inet6_dev *idev = in6_dev_get(dev);
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
if (unlikely(idev == NULL)) if (unlikely(!idev))
return NULL; return NULL;
rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, dev, 0); rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, dev, 0);
if (unlikely(rt == NULL)) { if (unlikely(!rt)) {
in6_dev_put(idev); in6_dev_put(idev);
goto out; goto out;
} }
...@@ -1238,23 +1238,23 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1238,23 +1238,23 @@ int ip6_route_add(struct fib6_config *cfg)
cfg->fc_metric = IP6_RT_PRIO_USER; cfg->fc_metric = IP6_RT_PRIO_USER;
err = -ENOBUFS; err = -ENOBUFS;
if (NULL != cfg->fc_nlinfo.nlh && if (cfg->fc_nlinfo.nlh &&
!(cfg->fc_nlinfo.nlh->nlmsg_flags&NLM_F_CREATE)) { !(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) {
table = fib6_get_table(net, cfg->fc_table); table = fib6_get_table(net, cfg->fc_table);
if (table == NULL) { if (!table) {
printk(KERN_WARNING "IPv6: NLM_F_CREATE should be specified when creating new route\n"); printk(KERN_WARNING "IPv6: NLM_F_CREATE should be specified when creating new route\n");
table = fib6_new_table(net, cfg->fc_table); table = fib6_new_table(net, cfg->fc_table);
} }
} else { } else {
table = fib6_new_table(net, cfg->fc_table); table = fib6_new_table(net, cfg->fc_table);
} }
if (table == NULL) {
if (!table)
goto out; goto out;
}
rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, NULL, DST_NOCOUNT); rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, NULL, DST_NOCOUNT);
if (rt == NULL) { if (!rt) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
...@@ -1303,8 +1303,9 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1303,8 +1303,9 @@ int ip6_route_add(struct fib6_config *cfg)
they would result in kernel looping; promote them to reject routes they would result in kernel looping; promote them to reject routes
*/ */
if ((cfg->fc_flags & RTF_REJECT) || if ((cfg->fc_flags & RTF_REJECT) ||
(dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK) (dev && (dev->flags & IFF_LOOPBACK) &&
&& !(cfg->fc_flags&RTF_LOCAL))) { !(addr_type & IPV6_ADDR_LOOPBACK) &&
!(cfg->fc_flags & RTF_LOCAL))) {
/* hold loopback dev/idev if we haven't done so. */ /* hold loopback dev/idev if we haven't done so. */
if (dev != net->loopback_dev) { if (dev != net->loopback_dev) {
if (dev) { if (dev) {
...@@ -1345,13 +1346,13 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1345,13 +1346,13 @@ int ip6_route_add(struct fib6_config *cfg)
some exceptions. --ANK some exceptions. --ANK
*/ */
err = -EINVAL; err = -EINVAL;
if (!(gwa_type&IPV6_ADDR_UNICAST)) if (!(gwa_type & IPV6_ADDR_UNICAST))
goto out; goto out;
grt = rt6_lookup(net, gw_addr, NULL, cfg->fc_ifindex, 1); grt = rt6_lookup(net, gw_addr, NULL, cfg->fc_ifindex, 1);
err = -EHOSTUNREACH; err = -EHOSTUNREACH;
if (grt == NULL) if (!grt)
goto out; goto out;
if (dev) { if (dev) {
if (dev != grt->rt6i_dev) { if (dev != grt->rt6i_dev) {
...@@ -1364,7 +1365,7 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1364,7 +1365,7 @@ int ip6_route_add(struct fib6_config *cfg)
dev_hold(dev); dev_hold(dev);
in6_dev_hold(grt->rt6i_idev); in6_dev_hold(grt->rt6i_idev);
} }
if (!(grt->rt6i_flags&RTF_GATEWAY)) if (!(grt->rt6i_flags & RTF_GATEWAY))
err = 0; err = 0;
dst_release(&grt->dst); dst_release(&grt->dst);
...@@ -1372,12 +1373,12 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1372,12 +1373,12 @@ int ip6_route_add(struct fib6_config *cfg)
goto out; goto out;
} }
err = -EINVAL; err = -EINVAL;
if (dev == NULL || (dev->flags&IFF_LOOPBACK)) if (!dev || (dev->flags & IFF_LOOPBACK))
goto out; goto out;
} }
err = -ENODEV; err = -ENODEV;
if (dev == NULL) if (!dev)
goto out; goto out;
if (!ipv6_addr_any(&cfg->fc_prefsrc)) { if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
...@@ -1474,7 +1475,7 @@ static int ip6_route_del(struct fib6_config *cfg) ...@@ -1474,7 +1475,7 @@ static int ip6_route_del(struct fib6_config *cfg)
int err = -ESRCH; int err = -ESRCH;
table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table);
if (table == NULL) if (!table)
return err; return err;
read_lock_bh(&table->tb6_lock); read_lock_bh(&table->tb6_lock);
...@@ -1486,7 +1487,7 @@ static int ip6_route_del(struct fib6_config *cfg) ...@@ -1486,7 +1487,7 @@ static int ip6_route_del(struct fib6_config *cfg)
if (fn) { if (fn) {
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) { for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
if (cfg->fc_ifindex && if (cfg->fc_ifindex &&
(rt->rt6i_dev == NULL || (!rt->rt6i_dev ||
rt->rt6i_dev->ifindex != cfg->fc_ifindex)) rt->rt6i_dev->ifindex != cfg->fc_ifindex))
continue; continue;
if (cfg->fc_flags & RTF_GATEWAY && if (cfg->fc_flags & RTF_GATEWAY &&
...@@ -1631,7 +1632,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src, ...@@ -1631,7 +1632,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src,
goto out; goto out;
nrt = ip6_rt_copy(rt, dest); nrt = ip6_rt_copy(rt, dest);
if (nrt == NULL) if (!nrt)
goto out; goto out;
nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE; nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE;
...@@ -1648,7 +1649,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src, ...@@ -1648,7 +1649,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src,
netevent.new = &nrt->dst; netevent.new = &nrt->dst;
call_netevent_notifiers(NETEVENT_REDIRECT, &netevent); call_netevent_notifiers(NETEVENT_REDIRECT, &netevent);
if (rt->rt6i_flags&RTF_CACHE) { if (rt->rt6i_flags & RTF_CACHE) {
ip6_del_rt(rt); ip6_del_rt(rt);
return; return;
} }
...@@ -1669,7 +1670,7 @@ static void rt6_do_pmtu_disc(const struct in6_addr *daddr, const struct in6_addr ...@@ -1669,7 +1670,7 @@ static void rt6_do_pmtu_disc(const struct in6_addr *daddr, const struct in6_addr
int allfrag = 0; int allfrag = 0;
again: again:
rt = rt6_lookup(net, daddr, saddr, ifindex, 0); rt = rt6_lookup(net, daddr, saddr, ifindex, 0);
if (rt == NULL) if (!rt)
return; return;
if (rt6_check_expired(rt)) { if (rt6_check_expired(rt)) {
...@@ -1817,7 +1818,7 @@ static struct rt6_info *rt6_get_route_info(struct net *net, ...@@ -1817,7 +1818,7 @@ static struct rt6_info *rt6_get_route_info(struct net *net,
struct fib6_table *table; struct fib6_table *table;
table = fib6_get_table(net, RT6_TABLE_INFO); table = fib6_get_table(net, RT6_TABLE_INFO);
if (table == NULL) if (!table)
return NULL; return NULL;
write_lock_bh(&table->tb6_lock); write_lock_bh(&table->tb6_lock);
...@@ -1876,7 +1877,7 @@ struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr, struct net_dev ...@@ -1876,7 +1877,7 @@ struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr, struct net_dev
struct fib6_table *table; struct fib6_table *table;
table = fib6_get_table(dev_net(dev), RT6_TABLE_DFLT); table = fib6_get_table(dev_net(dev), RT6_TABLE_DFLT);
if (table == NULL) if (!table)
return NULL; return NULL;
write_lock_bh(&table->tb6_lock); write_lock_bh(&table->tb6_lock);
...@@ -1921,7 +1922,7 @@ void rt6_purge_dflt_routers(struct net *net) ...@@ -1921,7 +1922,7 @@ void rt6_purge_dflt_routers(struct net *net)
/* NOTE: Keep consistent with rt6_get_dflt_router */ /* NOTE: Keep consistent with rt6_get_dflt_router */
table = fib6_get_table(net, RT6_TABLE_DFLT); table = fib6_get_table(net, RT6_TABLE_DFLT);
if (table == NULL) if (!table)
return; return;
restart: restart:
...@@ -2061,7 +2062,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev, ...@@ -2061,7 +2062,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
net->loopback_dev, 0); net->loopback_dev, 0);
struct neighbour *neigh; struct neighbour *neigh;
if (rt == NULL) { if (!rt) {
if (net_ratelimit()) if (net_ratelimit())
pr_warning("IPv6: Maximum number of routes reached," pr_warning("IPv6: Maximum number of routes reached,"
" consider increasing route/max_size.\n"); " consider increasing route/max_size.\n");
...@@ -2127,7 +2128,7 @@ static int fib6_remove_prefsrc(struct rt6_info *rt, void *arg) ...@@ -2127,7 +2128,7 @@ static int fib6_remove_prefsrc(struct rt6_info *rt, void *arg)
struct net *net = ((struct arg_dev_net_ip *)arg)->net; struct net *net = ((struct arg_dev_net_ip *)arg)->net;
struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
if (((void *)rt->rt6i_dev == dev || dev == NULL) && if (((void *)rt->rt6i_dev == dev || !dev) &&
rt != net->ipv6.ip6_null_entry && rt != net->ipv6.ip6_null_entry &&
ipv6_addr_equal(addr, &rt->rt6i_prefsrc.addr)) { ipv6_addr_equal(addr, &rt->rt6i_prefsrc.addr)) {
/* remove prefsrc entry */ /* remove prefsrc entry */
...@@ -2157,7 +2158,7 @@ static int fib6_ifdown(struct rt6_info *rt, void *arg) ...@@ -2157,7 +2158,7 @@ static int fib6_ifdown(struct rt6_info *rt, void *arg)
const struct arg_dev_net *adn = arg; const struct arg_dev_net *adn = arg;
const struct net_device *dev = adn->dev; const struct net_device *dev = adn->dev;
if ((rt->rt6i_dev == dev || dev == NULL) && if ((rt->rt6i_dev == dev || !dev) &&
rt != adn->net->ipv6.ip6_null_entry) { rt != adn->net->ipv6.ip6_null_entry) {
RT6_TRACE("deleted by ifdown %p\n", rt); RT6_TRACE("deleted by ifdown %p\n", rt);
return -1; return -1;
...@@ -2194,7 +2195,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg) ...@@ -2194,7 +2195,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
*/ */
idev = __in6_dev_get(arg->dev); idev = __in6_dev_get(arg->dev);
if (idev == NULL) if (!idev)
return 0; return 0;
/* For administrative MTU increase, there is no way to discover /* For administrative MTU increase, there is no way to discover
...@@ -2374,7 +2375,7 @@ static int rt6_fill_node(struct net *net, ...@@ -2374,7 +2375,7 @@ static int rt6_fill_node(struct net *net,
} }
nlh = nlmsg_put(skb, pid, seq, type, sizeof(*rtm), flags); nlh = nlmsg_put(skb, pid, seq, type, sizeof(*rtm), flags);
if (nlh == NULL) if (!nlh)
return -EMSGSIZE; return -EMSGSIZE;
rtm = nlmsg_data(nlh); rtm = nlmsg_data(nlh);
...@@ -2388,25 +2389,25 @@ static int rt6_fill_node(struct net *net, ...@@ -2388,25 +2389,25 @@ static int rt6_fill_node(struct net *net,
table = RT6_TABLE_UNSPEC; table = RT6_TABLE_UNSPEC;
rtm->rtm_table = table; rtm->rtm_table = table;
NLA_PUT_U32(skb, RTA_TABLE, table); NLA_PUT_U32(skb, RTA_TABLE, table);
if (rt->rt6i_flags&RTF_REJECT) if (rt->rt6i_flags & RTF_REJECT)
rtm->rtm_type = RTN_UNREACHABLE; rtm->rtm_type = RTN_UNREACHABLE;
else if (rt->rt6i_flags&RTF_LOCAL) else if (rt->rt6i_flags & RTF_LOCAL)
rtm->rtm_type = RTN_LOCAL; rtm->rtm_type = RTN_LOCAL;
else if (rt->rt6i_dev && (rt->rt6i_dev->flags&IFF_LOOPBACK)) else if (rt->rt6i_dev && (rt->rt6i_dev->flags & IFF_LOOPBACK))
rtm->rtm_type = RTN_LOCAL; rtm->rtm_type = RTN_LOCAL;
else else
rtm->rtm_type = RTN_UNICAST; rtm->rtm_type = RTN_UNICAST;
rtm->rtm_flags = 0; rtm->rtm_flags = 0;
rtm->rtm_scope = RT_SCOPE_UNIVERSE; rtm->rtm_scope = RT_SCOPE_UNIVERSE;
rtm->rtm_protocol = rt->rt6i_protocol; rtm->rtm_protocol = rt->rt6i_protocol;
if (rt->rt6i_flags&RTF_DYNAMIC) if (rt->rt6i_flags & RTF_DYNAMIC)
rtm->rtm_protocol = RTPROT_REDIRECT; rtm->rtm_protocol = RTPROT_REDIRECT;
else if (rt->rt6i_flags & RTF_ADDRCONF) else if (rt->rt6i_flags & RTF_ADDRCONF)
rtm->rtm_protocol = RTPROT_KERNEL; rtm->rtm_protocol = RTPROT_KERNEL;
else if (rt->rt6i_flags&RTF_DEFAULT) else if (rt->rt6i_flags & RTF_DEFAULT)
rtm->rtm_protocol = RTPROT_RA; rtm->rtm_protocol = RTPROT_RA;
if (rt->rt6i_flags&RTF_CACHE) if (rt->rt6i_flags & RTF_CACHE)
rtm->rtm_flags |= RTM_F_CLONED; rtm->rtm_flags |= RTM_F_CLONED;
if (dst) { if (dst) {
...@@ -2546,7 +2547,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void ...@@ -2546,7 +2547,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
} }
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
if (skb == NULL) { if (!skb) {
err = -ENOBUFS; err = -ENOBUFS;
goto errout; goto errout;
} }
...@@ -2581,10 +2582,10 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info) ...@@ -2581,10 +2582,10 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
int err; int err;
err = -ENOBUFS; err = -ENOBUFS;
seq = info->nlh != NULL ? info->nlh->nlmsg_seq : 0; seq = info->nlh ? info->nlh->nlmsg_seq : 0;
skb = nlmsg_new(rt6_nlmsg_size(), gfp_any()); skb = nlmsg_new(rt6_nlmsg_size(), gfp_any());
if (skb == NULL) if (!skb)
goto errout; goto errout;
err = rt6_fill_node(net, skb, rt, NULL, NULL, 0, err = rt6_fill_node(net, skb, rt, NULL, NULL, 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment