Commit 53608418 authored by Hideaki Yoshifuji's avatar Hideaki Yoshifuji

[IPV6]: Use the cheaper ipv6_addr_is_multicast() for ipv6_addr_type() where possible.

parent 8e5afcc7
...@@ -111,7 +111,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -111,7 +111,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (ipv6_addr_type(addr) & IPV6_ADDR_MULTICAST) if (ipv6_addr_is_multicast(addr))
return -EINVAL; return -EINVAL;
if (ipv6_chk_addr(addr, NULL, 0)) if (ipv6_chk_addr(addr, NULL, 0))
return -EINVAL; return -EINVAL;
......
...@@ -218,7 +218,6 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp) ...@@ -218,7 +218,6 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp)
struct inet6_skb_parm *opt = (struct inet6_skb_parm *)skb->cb; struct inet6_skb_parm *opt = (struct inet6_skb_parm *)skb->cb;
struct in6_addr *addr; struct in6_addr *addr;
struct in6_addr daddr; struct in6_addr daddr;
int addr_type;
int n, i; int n, i;
struct ipv6_rt_hdr *hdr; struct ipv6_rt_hdr *hdr;
...@@ -233,7 +232,7 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp) ...@@ -233,7 +232,7 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp)
hdr = (struct ipv6_rt_hdr *) skb->h.raw; hdr = (struct ipv6_rt_hdr *) skb->h.raw;
if ((ipv6_addr_type(&skb->nh.ipv6h->daddr)&IPV6_ADDR_MULTICAST) || if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr) ||
skb->pkt_type != PACKET_HOST) { skb->pkt_type != PACKET_HOST) {
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
...@@ -293,9 +292,7 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp) ...@@ -293,9 +292,7 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp, unsigned int *nhoffp)
addr = rthdr->addr; addr = rthdr->addr;
addr += i - 1; addr += i - 1;
addr_type = ipv6_addr_type(addr); if (ipv6_addr_is_multicast(addr)) {
if (addr_type&IPV6_ADDR_MULTICAST) {
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
......
...@@ -175,7 +175,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -175,7 +175,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, struct in6_addr *addr)
struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk);
int err; int err;
if (!(ipv6_addr_type(addr) & IPV6_ADDR_MULTICAST)) if (!ipv6_addr_is_multicast(addr))
return -EINVAL; return -EINVAL;
mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL); mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL);
...@@ -348,7 +348,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk, ...@@ -348,7 +348,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr; source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr;
group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr; group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr;
if (!(ipv6_addr_type(group) & IPV6_ADDR_MULTICAST)) if (!ipv6_addr_is_multicast(group))
return -EINVAL; return -EINVAL;
idev = ip6_mc_find_dev(group, pgsr->gsr_interface); idev = ip6_mc_find_dev(group, pgsr->gsr_interface);
...@@ -457,7 +457,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) ...@@ -457,7 +457,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf)
group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
if (!(ipv6_addr_type(group) & IPV6_ADDR_MULTICAST)) if (!ipv6_addr_is_multicast(group))
return -EINVAL; return -EINVAL;
if (gsf->gf_fmode != MCAST_INCLUDE && if (gsf->gf_fmode != MCAST_INCLUDE &&
gsf->gf_fmode != MCAST_EXCLUDE) gsf->gf_fmode != MCAST_EXCLUDE)
...@@ -529,7 +529,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, ...@@ -529,7 +529,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
if (!(ipv6_addr_type(group) & IPV6_ADDR_MULTICAST)) if (!ipv6_addr_is_multicast(group))
return -EINVAL; return -EINVAL;
idev = ip6_mc_find_dev(group, gsf->gf_interface); idev = ip6_mc_find_dev(group, gsf->gf_interface);
......
...@@ -277,25 +277,21 @@ static int ndisc_constructor(struct neighbour *neigh) ...@@ -277,25 +277,21 @@ static int ndisc_constructor(struct neighbour *neigh)
struct in6_addr *addr = (struct in6_addr*)&neigh->primary_key; struct in6_addr *addr = (struct in6_addr*)&neigh->primary_key;
struct net_device *dev = neigh->dev; struct net_device *dev = neigh->dev;
struct inet6_dev *in6_dev = in6_dev_get(dev); struct inet6_dev *in6_dev = in6_dev_get(dev);
int addr_type; int is_multicast = ipv6_addr_is_multicast(addr);
if (in6_dev == NULL) if (in6_dev == NULL)
return -EINVAL; return -EINVAL;
addr_type = ipv6_addr_type(addr);
if (in6_dev->nd_parms) if (in6_dev->nd_parms)
neigh->parms = in6_dev->nd_parms; neigh->parms = in6_dev->nd_parms;
if (addr_type&IPV6_ADDR_MULTICAST) neigh->type = is_multicast ? RTN_MULTICAST : RTN_UNICAST;
neigh->type = RTN_MULTICAST;
else
neigh->type = RTN_UNICAST;
if (dev->hard_header == NULL) { if (dev->hard_header == NULL) {
neigh->nud_state = NUD_NOARP; neigh->nud_state = NUD_NOARP;
neigh->ops = &ndisc_direct_ops; neigh->ops = &ndisc_direct_ops;
neigh->output = neigh->ops->queue_xmit; neigh->output = neigh->ops->queue_xmit;
} else { } else {
if (addr_type&IPV6_ADDR_MULTICAST) { if (is_multicast) {
neigh->nud_state = NUD_NOARP; neigh->nud_state = NUD_NOARP;
ndisc_mc_map(addr, neigh->ha, dev, 1); ndisc_mc_map(addr, neigh->ha, dev, 1);
} else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) {
...@@ -355,7 +351,7 @@ ndisc_build_ll_hdr(struct sk_buff *skb, struct net_device *dev, ...@@ -355,7 +351,7 @@ ndisc_build_ll_hdr(struct sk_buff *skb, struct net_device *dev,
unsigned char *h_dest = NULL; unsigned char *h_dest = NULL;
if (dev->hard_header) { if (dev->hard_header) {
if (ipv6_addr_type(daddr) & IPV6_ADDR_MULTICAST) { if (ipv6_addr_is_multicast(daddr)) {
ndisc_mc_map(daddr, ha, dev, 1); ndisc_mc_map(daddr, ha, dev, 1);
h_dest = ha; h_dest = ha;
} else if (neigh) { } else if (neigh) {
...@@ -711,7 +707,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -711,7 +707,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
struct neighbour *neigh; struct neighbour *neigh;
int addr_type = ipv6_addr_type(saddr); int addr_type = ipv6_addr_type(saddr);
if (ipv6_addr_type(&msg->target)&IPV6_ADDR_MULTICAST) { if (ipv6_addr_is_multicast(&msg->target)) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_WARNING "ICMP NS: target address is multicast\n"); printk(KERN_WARNING "ICMP NS: target address is multicast\n");
return; return;
...@@ -797,9 +793,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -797,9 +793,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
} }
if (addr_type & IPV6_ADDR_UNICAST) { if (addr_type & IPV6_ADDR_UNICAST) {
int inc = ipv6_addr_type(daddr)&IPV6_ADDR_MULTICAST; if (ipv6_addr_is_multicast(daddr))
if (inc)
nd_tbl.stats.rcv_probes_mcast++; nd_tbl.stats.rcv_probes_mcast++;
else else
nd_tbl.stats.rcv_probes_ucast++; nd_tbl.stats.rcv_probes_ucast++;
...@@ -841,7 +835,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -841,7 +835,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
} }
if (addr_type & IPV6_ADDR_UNICAST) { if (addr_type & IPV6_ADDR_UNICAST) {
int inc = ipv6_addr_type(daddr)&IPV6_ADDR_MULTICAST; int inc = ipv6_addr_is_multicast(daddr);
if (inc) if (inc)
nd_tbl.stats.rcv_probes_mcast++; nd_tbl.stats.rcv_probes_mcast++;
else else
...@@ -870,7 +864,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -870,7 +864,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
(addr_type & IPV6_ADDR_UNICAST || (addr_type & IPV6_ADDR_UNICAST ||
addr_type == IPV6_ADDR_ANY) && addr_type == IPV6_ADDR_ANY) &&
pneigh_lookup(&nd_tbl, &msg->target, dev, 0)) { pneigh_lookup(&nd_tbl, &msg->target, dev, 0)) {
int inc = ipv6_addr_type(daddr)&IPV6_ADDR_MULTICAST; int inc = ipv6_addr_is_multicast(daddr);
if (skb->stamp.tv_sec == 0 || if (skb->stamp.tv_sec == 0 ||
skb->pkt_type == PACKET_HOST || skb->pkt_type == PACKET_HOST ||
...@@ -929,13 +923,13 @@ static void ndisc_recv_na(struct sk_buff *skb) ...@@ -929,13 +923,13 @@ static void ndisc_recv_na(struct sk_buff *skb)
return; return;
} }
if (ipv6_addr_type(&msg->target)&IPV6_ADDR_MULTICAST) { if (ipv6_addr_is_multicast(&msg->target)) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_WARNING "NDISC NA: target address is multicast\n"); printk(KERN_WARNING "NDISC NA: target address is multicast\n");
return; return;
} }
if ((ipv6_addr_type(daddr)&IPV6_ADDR_MULTICAST) && if (ipv6_addr_is_multicast(daddr) &&
msg->icmph.icmp6_solicited) { msg->icmph.icmp6_solicited) {
ND_PRINTK0("NDISC: solicited NA is multicasted\n"); ND_PRINTK0("NDISC: solicited NA is multicasted\n");
return; return;
...@@ -1229,7 +1223,7 @@ static void ndisc_redirect_rcv(struct sk_buff *skb) ...@@ -1229,7 +1223,7 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
target = (struct in6_addr *) (icmph + 1); target = (struct in6_addr *) (icmph + 1);
dest = target + 1; dest = target + 1;
if (ipv6_addr_type(dest) & IPV6_ADDR_MULTICAST) { if (ipv6_addr_is_multicast(dest)) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_WARNING "ICMP redirect for multicast addr\n"); printk(KERN_WARNING "ICMP redirect for multicast addr\n");
return; return;
......
...@@ -81,7 +81,7 @@ struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num, ...@@ -81,7 +81,7 @@ struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num,
struct in6_addr *loc_addr, struct in6_addr *rmt_addr) struct in6_addr *loc_addr, struct in6_addr *rmt_addr)
{ {
struct hlist_node *node; struct hlist_node *node;
int addr_type = ipv6_addr_type(loc_addr); int is_multicast = ipv6_addr_is_multicast(loc_addr);
sk_for_each_from(sk, node) sk_for_each_from(sk, node)
if (inet_sk(sk)->num == num) { if (inet_sk(sk)->num == num) {
...@@ -94,7 +94,7 @@ struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num, ...@@ -94,7 +94,7 @@ struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num,
if (!ipv6_addr_any(&np->rcv_saddr)) { if (!ipv6_addr_any(&np->rcv_saddr)) {
if (!ipv6_addr_cmp(&np->rcv_saddr, loc_addr)) if (!ipv6_addr_cmp(&np->rcv_saddr, loc_addr))
goto found; goto found;
if ((addr_type & IPV6_ADDR_MULTICAST) && if (is_multicast &&
inet6_mc_check(sk, loc_addr, rmt_addr)) inet6_mc_check(sk, loc_addr, rmt_addr))
goto found; goto found;
continue; continue;
......
...@@ -658,7 +658,7 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp) ...@@ -658,7 +658,7 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
/* /*
* Multicast receive code * Multicast receive code
*/ */
if (ipv6_addr_type(daddr) & IPV6_ADDR_MULTICAST) { if (ipv6_addr_is_multicast(daddr)) {
udpv6_mcast_deliver(uh, saddr, daddr, skb); udpv6_mcast_deliver(uh, saddr, daddr, skb);
return 0; return 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