Skip to contentSkip to conversation

Add link and site-local scope inline

PATCH In review Brian Haley 2 participants 11 messages Apr 6, 2007 4 messages not in the archive

Subsystems (7)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/4 Add link and site-local scope inline

Add link and site-local scope inline to avoid calls to ipv6_addr_type().

---
  include/net/ipv6.h               |   10 ++++++++++
  net/dccp/ipv6.c                  |    2 +-
  net/ipv6/addrconf.c              |    6 +++---
  net/ipv6/af_inet6.c              |    2 +-
  net/ipv6/datagram.c              |   11 ++++-------
  net/ipv6/inet6_connection_sock.c |    2 +-
  net/ipv6/ip6_output.c            |    2 +-
  net/ipv6/mcast.c                 |    8 +++-----
  net/ipv6/ndisc.c                 |    8 ++++----
  net/ipv6/raw.c                   |    4 ++--
  net/ipv6/tcp_ipv6.c              |    2 +-
  net/ipv6/udp.c                   |    4 ++--
  net/sctp/ipv6.c                  |   16 +++++++---------
  13 files changed, 40 insertions(+), 37 deletions(-)
include/net/ipv6.h +10 -0
index 00328b7..d473789 100644
@@ -429,6 +429,16 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add
  	return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
  }
 
+static inline int ipv6_addr_scope_linklocal(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] & htonl(0xFFC00000)) = htonl(0xFE800000));
+}
+
+static inline int ipv6_addr_scope_sitelocal(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] & htonl(0xFFC00000)) = htonl(0xFEC00000));
+}
+
  /*
   *	Prototypes exported by ipv6
   */
net/dccp/ipv6.c +1 -1
index 64eac25..14a0f12 100644
@@ -476,7 +476,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
 
  	/* So that link locals have meaning */
  	if (!sk->sk_bound_dev_if &&
-	    ipv6_addr_type(&ireq6->rmt_addr) & IPV6_ADDR_LINKLOCAL)
+	    ipv6_addr_scope_linklocal(&ireq6->rmt_addr))
  		ireq6->iif = inet6_iif(skb);
 
  	/*
net/ipv6/addrconf.c +3 -3
index 47d3adf..2d4fe24 100644
@@ -2634,7 +2634,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
  	if (ifp->idev->cnf.forwarding = 0 &&
  	    ifp->idev->cnf.rtr_solicits > 0 &&
  	    (dev->flags&IFF_LOOPBACK) = 0 &&
-	    (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
+	    ipv6_addr_scope_linklocal(&ifp->addr)) {
  		struct in6_addr all_routers;
 
  		ipv6_addr_all_routers(&all_routers);
@@ -3155,7 +3155,7 @@ static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
  	u8 scope = RT_SCOPE_UNIVERSE;
  	int ifindex = ifmca->idev->dev->ifindex;
 
-	if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
+	if (ipv6_addr_scope_sitelocal(&ifmca->mca_addr))
  		scope = RT_SCOPE_SITE;
 
  	nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
@@ -3180,7 +3180,7 @@ static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
  	u8 scope = RT_SCOPE_UNIVERSE;
  	int ifindex = ifaca->aca_idev->dev->ifindex;
 
-	if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
+	if (ipv6_addr_scope_sitelocal(&ifaca->aca_addr))
  		scope = RT_SCOPE_SITE;
 
  	nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
net/ipv6/af_inet6.c +1 -1
index df31cdd..24618cf 100644
@@ -431,7 +431,7 @@ int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
 
  		sin->sin6_port = inet->sport;
  	}
-	if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+	if (ipv6_addr_scope_linklocal(&sin->sin6_addr))
  		sin->sin6_scope_id = sk->sk_bound_dev_if;
  	*uaddr_len = sizeof(*sin);
  	return(0);
net/ipv6/datagram.c +4 -7
index 4a355fe..a8612b2 100644
@@ -323,7 +323,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
  				sin->sin6_flowinfo   					(*(__be32 *)(nh + serr->addr_offset - 24) &
  					 IPV6_FLOWINFO_MASK);
-			if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+			if (ipv6_addr_scope_linklocal(&sin->sin6_addr))
  				sin->sin6_scope_id = IP6CB(skb)->iif;
  		} else {
  			ipv6_addr_set(&sin->sin6_addr, 0, 0,
@@ -343,7 +343,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
  			ipv6_addr_copy(&sin->sin6_addr, &ipv6_hdr(skb)->saddr);
  			if (np->rxopt.all)
  				datagram_recv_ctl(sk, msg, skb);
-			if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+			if (ipv6_addr_scope_linklocal(&sin->sin6_addr))
  				sin->sin6_scope_id = IP6CB(skb)->iif;
  		} else {
  			struct inet_sock *inet = inet_sk(sk);
@@ -504,7 +504,6 @@ int datagram_send_ctl(struct msghdr *msg, struct flowi *fl,
  	int err = 0;
 
  	for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
-		int addr_type;
  		struct net_device *dev = NULL;
 
  		if (!CMSG_OK(msg, cmsg)) {
@@ -531,12 +530,10 @@ int datagram_send_ctl(struct msghdr *msg, struct flowi *fl,
  				fl->oif = src_info->ipi6_ifindex;
  			}
 
-			addr_type = ipv6_addr_type(&src_info->ipi6_addr);
-
-			if (addr_type = IPV6_ADDR_ANY)
+			if (ipv6_addr_any(&src_info->ipi6_addr))
  				break;
 
-			if (addr_type & IPV6_ADDR_LINKLOCAL) {
+			if (ipv6_addr_scope_linklocal(&src_info->ipi6_addr)) {
  				if (!src_info->ipi6_ifindex)
  					return -EINVAL;
  				else {
net/ipv6/inet6_connection_sock.c +1 -1
index 116f94a..7cefe18 100644
@@ -133,7 +133,7 @@ void inet6_csk_addr2sockaddr(struct sock *sk, struct sockaddr * uaddr)
  	sin6->sin6_flowinfo = 0;
  	sin6->sin6_scope_id = 0;
  	if (sk->sk_bound_dev_if &&
-	    ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+	    ipv6_addr_scope_linklocal(&sin6->sin6_addr))
  		sin6->sin6_scope_id = sk->sk_bound_dev_if;
  }
 
net/ipv6/ip6_output.c +1 -1
index 78317a4..f6aa338 100644
@@ -351,7 +351,7 @@ static int ip6_forward_proxy_check(struct sk_buff *skb)
  	 * address, so signal the sender and discard the packet. This
  	 * behavior is clarified by the MIPv6 specification.
  	 */
-	if (ipv6_addr_type(&hdr->daddr) & IPV6_ADDR_LINKLOCAL) {
+	if (ipv6_addr_scope_linklocal(&hdr->daddr)) {
  		dst_link_failure(skb);
  		return -1;
  	}
net/ipv6/mcast.c +3 -5
index 6c27589..d2d31a2 100644
@@ -1171,7 +1171,7 @@ int igmp6_event_query(struct sk_buff *skb)
  	len -= skb_network_header_len(skb);
 
  	/* Drop queries with not link local source */
-	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL))
+	if (!ipv6_addr_scope_linklocal(&ipv6_hdr(skb)->saddr))
  		return -EINVAL;
 
  	idev = in6_dev_get(skb->dev);
@@ -1286,7 +1286,6 @@ int igmp6_event_report(struct sk_buff *skb)
  	struct in6_addr *addrp;
  	struct inet6_dev *idev;
  	struct icmp6hdr *hdr;
-	int addr_type;
 
  	/* Our own report looped back. Ignore it. */
  	if (skb->pkt_type = PACKET_LOOPBACK)
@@ -1303,9 +1302,8 @@ int igmp6_event_report(struct sk_buff *skb)
  	hdr = icmp6_hdr(skb);
 
  	/* Drop reports with not link local source */
-	addr_type = ipv6_addr_type(&ipv6_hdr(skb)->saddr);
-	if (addr_type != IPV6_ADDR_ANY &&
-	    !(addr_type&IPV6_ADDR_LINKLOCAL))
+	if (!ipv6_addr_any(&ipv6_hdr(skb)->saddr) &&
+	    !ipv6_addr_scope_linklocal(&ipv6_hdr(skb)->saddr))
  		return -EINVAL;
 
  	addrp = (struct in6_addr *) (hdr + 1);
net/ipv6/ndisc.c +4 -4
index b1cf708..b500011 100644
@@ -1115,7 +1115,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
 
  	optlen = (skb->tail - skb->transport_header) - sizeof(struct ra_msg);
 
-	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
+	if (!ipv6_addr_scope_linklocal(&ipv6_hdr(skb)->saddr)) {
  		ND_PRINTK2(KERN_WARNING
  			   "ICMPv6 RA: source address is not link-local.\n");
  		return;
@@ -1356,7 +1356,7 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
  	int optlen;
  	u8 *lladdr = NULL;
 
-	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
+	if (!ipv6_addr_scope_linklocal(&ipv6_hdr(skb)->saddr)) {
  		ND_PRINTK2(KERN_WARNING
  			   "ICMPv6 Redirect: source address is not link-local.\n");
  		return;
@@ -1383,7 +1383,7 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
 
  	if (ipv6_addr_equal(dest, target)) {
  		on_link = 1;
-	} else if (!(ipv6_addr_type(target) & IPV6_ADDR_LINKLOCAL)) {
+	} else if (!ipv6_addr_scope_linklocal(target)) {
  		ND_PRINTK2(KERN_WARNING
  			   "ICMPv6 Redirect: target address is not link-local.\n");
  		return;
@@ -1459,7 +1459,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
  	}
 
  	if (!ipv6_addr_equal(&ipv6_hdr(skb)->daddr, target) &&
-	    !(ipv6_addr_type(target) & IPV6_ADDR_LINKLOCAL)) {
+	    !ipv6_addr_scope_linklocal(target)) {
  		ND_PRINTK2(KERN_WARNING
  			"ICMPv6 Redirect: target address is not link-local.\n");
  		return;
net/ipv6/raw.c +2 -2
index 9592930..771fa0e 100644
@@ -442,7 +442,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
  		ipv6_addr_copy(&sin6->sin6_addr, &ipv6_hdr(skb)->saddr);
  		sin6->sin6_flowinfo = 0;
  		sin6->sin6_scope_id = 0;
-		if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+		if (ipv6_addr_scope_linklocal(&sin6->sin6_addr))
  			sin6->sin6_scope_id = IP6CB(skb)->iif;
  	}
 
@@ -750,7 +750,7 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
 
  		if (addr_len >= sizeof(struct sockaddr_in6) &&
  		    sin6->sin6_scope_id &&
-		    ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
+		    ipv6_addr_scope_linklocal(daddr))
  			fl.oif = sin6->sin6_scope_id;
  	} else {
  		if (sk->sk_state != TCP_ESTABLISHED)
net/ipv6/tcp_ipv6.c +1 -1
index f0f7dc6..537978c 100644
@@ -1287,7 +1287,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
 
  	/* So that link locals have meaning */
  	if (!sk->sk_bound_dev_if &&
-	    ipv6_addr_type(&treq->rmt_addr) & IPV6_ADDR_LINKLOCAL)
+	    ipv6_addr_scope_linklocal(&treq->rmt_addr))
  		treq->iif = inet6_iif(skb);
 
  	if (isn = 0)
net/ipv6/udp.c +2 -2
index bd2856f..c0b5fe3 100644
@@ -182,7 +182,7 @@ try_again:
  		else {
  			ipv6_addr_copy(&sin6->sin6_addr,
  				       &ipv6_hdr(skb)->saddr);
-			if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+			if (ipv6_addr_scope_linklocal(&sin6->sin6_addr))
  				sin6->sin6_scope_id = IP6CB(skb)->iif;
  		}
 
@@ -680,7 +680,7 @@ do_udp_sendmsg:
 
  		if (addr_len >= sizeof(struct sockaddr_in6) &&
  		    sin6->sin6_scope_id &&
-		    ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
+		    ipv6_addr_scope_linklocal(daddr))
  			fl.oif = sin6->sin6_scope_id;
  	} else {
  		if (sk->sk_state != TCP_ESTABLISHED)
net/sctp/ipv6.c +7 -9
index 5b0cdda..c1f4a8f 100644
@@ -199,7 +199,7 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport,
 
  	fl.fl6_flowlabel = np->flow_label;
  	IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel);
-	if (ipv6_addr_type(&fl.fl6_src) & IPV6_ADDR_LINKLOCAL)
+	if (ipv6_addr_scope_linklocal(&fl.fl6_src))
  		fl.oif = transport->saddr.v6.sin6_scope_id;
  	else
  		fl.oif = sk->sk_bound_dev_if;
@@ -231,7 +231,7 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
 
  	memset(&fl, 0, sizeof(fl));
  	ipv6_addr_copy(&fl.fl6_dst, &daddr->v6.sin6_addr);
-	if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
+	if (ipv6_addr_scope_linklocal(&daddr->v6.sin6_addr))
  		fl.oif = daddr->v6.sin6_scope_id;
 
 
@@ -500,7 +500,7 @@ static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
  	if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
  		return 0;
  	/* If this is a linklocal address, compare the scope_id. */
-	if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) {
+	if (ipv6_addr_scope_linklocal(&addr1->v6.sin6_addr)) {
  		if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
  		    (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) {
  			return 0;
@@ -749,7 +749,7 @@ static void sctp_inet6_event_msgname(struct sctp_ulpevent *event,
 
  		sin6from = &asoc->peer.primary_addr.v6;
  		ipv6_addr_copy(&sin6->sin6_addr, &sin6from->sin6_addr);
-		if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+		if (ipv6_addr_scope_linklocal(&sin6->sin6_addr))
  			sin6->sin6_scope_id = sin6from->sin6_scope_id;
  	}
  }
@@ -777,7 +777,7 @@ static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
 
  		/* Otherwise, just copy the v6 address. */
  		ipv6_addr_copy(&sin6->sin6_addr, &ipv6_hdr(skb)->saddr);
-		if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) {
+		if (ipv6_addr_scope_linklocal(&sin6->sin6_addr)) {
  			struct sctp_ulpevent *ev = sctp_skb2event(skb);
  			sin6->sin6_scope_id = ev->iif;
  		}
@@ -835,10 +835,9 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
  	if (addr->sa.sa_family != AF_INET6)
  		af = sctp_get_af_specific(addr->sa.sa_family);
  	else {
-		int type = ipv6_addr_type(&addr->v6.sin6_addr);
  		struct net_device *dev;
 
-		if (type & IPV6_ADDR_LINKLOCAL) {
+		if (ipv6_addr_scope_linklocal(&addr->v6.sin6_addr)) {
  			if (!addr->v6.sin6_scope_id)
  				return 0;
  			dev = dev_get_by_index(addr->v6.sin6_scope_id);
@@ -862,10 +861,9 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
  	if (addr->sa.sa_family != AF_INET6)
  		af = sctp_get_af_specific(addr->sa.sa_family);
  	else {
-		int type = ipv6_addr_type(&addr->v6.sin6_addr);
  		struct net_device *dev;
 
-		if (type & IPV6_ADDR_LINKLOCAL) {
+		if (ipv6_addr_scope_linklocal(&addr->v6.sin6_addr)) {
  			if (!addr->v6.sin6_scope_id)
  				return 0;
  			dev = dev_get_by_index(addr->v6.sin6_scope_id);
Signature · 1 line
1.5.0.3
#3 lore raw
Quoted 6 lines · YOSHIFUJI Hideaki / ????

In article <[email protected]> (at Thu, 05 Apr 2007 23:21:05 -0400), Brian Haley <[email protected]> says:

Quoted 2 lines

Add link and site-local scope inline to avoid calls to ipv6_addr_type().

I disagree. Multicast scopes should also be handled appropriately.

Yes, I totally missed that ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr)) in __ipv6_addr_type(), so the linklocal inline probably isn't worth it since it would have to be something like:

static inline int ipv6_addr_scope_linklocal(const struct in6_addr *a) {
return ((a->s6_addr32[0] & htonl(0xFFC00000)) = htonl(0xFE800000) ||

         ((a->s6_addr32[0] & htonl(0xFF000000)) = htonl(0xFF000000) &&
          ((a)->s6_addr[1] & 0x0f) = IPV6_ADDR_SCOPE_LINKLOCAL)))
}

That's not that clean an inline anymore, but still doable...

I'll clean-up the rest based on your comments and re-send.

-Brian

#4 lore raw

In article <[email protected]> (at Fri, 06 Apr 2007 02:37:52 -0400), Brian Haley <[email protected]> says:

Quoted 8 lines

static inline int ipv6_addr_scope_linklocal(const struct in6_addr *a) {
return ((a->s6_addr32[0] & htonl(0xFFC00000)) = htonl(0xFE800000) ||

         ((a->s6_addr32[0] & htonl(0xFF000000)) = htonl(0xFF000000) &&
          ((a)->s6_addr[1] & 0x0f) = IPV6_ADDR_SCOPE_LINKLOCAL)))
}

That's not that clean an inline anymore, but still doable...

I would prefer to have ipv6_addr_linklocal() and
ipv6_addr_mc_linklocal() aligning with RFC3493.

--yoshfuji

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 151538c13022864224f5ff440e1147f884abb492.1175794415.git.brian.haley@hp.com

#7 lore raw

PATCH 2/4 Add multicast address type inline

Add multicast address type inline to avoid calls to ipv6_addr_type().

---
 include/net/ipv6.h    |    5 +++++
 net/ipv6/icmp.c       |   12 ++++--------
 net/ipv6/ip6_tunnel.c |    4 ++--
 net/ipv6/route.c      |    4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)
include/net/ipv6.h +5 -0
index d473789..a888b0e 100644
@@ -439,6 +439,11 @@ static inline int ipv6_addr_scope_sitelocal(const struct in6_addr *a)
 	return ((a->s6_addr32[0] & htonl(0xFFC00000)) == htonl(0xFEC00000));
 }
 
+static inline int ipv6_addr_type_multicast(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000));
+}
+
 /*
  *	Prototypes exported by ipv6
  */
net/ipv6/icmp.c +4 -8
index e94992a..709037f 100644
@@ -312,7 +312,6 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
 	struct flowi fl;
 	struct icmpv6_msg msg;
 	int iif = 0;
-	int addr_type = 0;
 	int len;
 	int hlimit, tclass;
 	int err = 0;
@@ -327,8 +326,6 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
 	 *	Rule (e.1) is enforced by not using icmpv6_send
 	 *	in any code that processes icmp errors.
 	 */
-	addr_type = ipv6_addr_type(&hdr->daddr);
-
 	if (ipv6_chk_addr(&hdr->daddr, skb->dev, 0))
 		saddr = &hdr->daddr;
 
@@ -336,7 +333,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
 	 *	Dest addr check
 	 */
 
-	if ((addr_type & IPV6_ADDR_MULTICAST || skb->pkt_type != PACKET_HOST)) {
+	if (ipv6_addr_type_multicast(&hdr->daddr) || skb->pkt_type != PACKET_HOST) {
 		if (type != ICMPV6_PKT_TOOBIG &&
 		    !(type == ICMPV6_PARAMPROB &&
 		      code == ICMPV6_UNK_OPTION &&
@@ -346,13 +343,11 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
 		saddr = NULL;
 	}
 
-	addr_type = ipv6_addr_type(&hdr->saddr);
-
 	/*
 	 *	Source addr check
 	 */
 
-	if (addr_type & IPV6_ADDR_LINKLOCAL)
+	if (ipv6_addr_scope_linklocal(&hdr->saddr))
 		iif = skb->dev->ifindex;
 
 	/*
@@ -361,7 +356,8 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
 	 *	We check unspecified / multicast addresses here,
 	 *	and anycast addresses will be checked later.
 	 */
-	if ((addr_type == IPV6_ADDR_ANY) || (addr_type & IPV6_ADDR_MULTICAST)) {
+	if (ipv6_addr_any(&hdr->saddr) ||
+	    ipv6_addr_type_multicast(&hdr->saddr)) {
 		LIMIT_NETDEBUG(KERN_DEBUG "icmpv6_send: addr_any/mcast source\n");
 		return;
 	}
net/ipv6/ip6_tunnel.c +2 -2
index a0902fb..0dd1f63 100644
@@ -1111,8 +1111,8 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
 	dev->iflink = p->link;
 
 	if (p->flags & IP6_TNL_F_CAP_XMIT) {
-		int strict = (ipv6_addr_type(&p->raddr) &
-			      (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
+		int strict = ipv6_addr_type_multicast(&p->raddr) ||
+			     ipv6_addr_scope_linklocal(&p->raddr);
 
 		struct rt6_info *rt = rt6_lookup(&p->raddr, &p->laddr,
 						 p->link, strict);
net/ipv6/route.c +2 -2
index 53d79ac..32c6398 100644
@@ -227,8 +227,8 @@ static __inline__ int rt6_check_expired(const struct rt6_info *rt)
 
 static inline int rt6_need_strict(struct in6_addr *daddr)
 {
-	return (ipv6_addr_type(daddr) &
-		(IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL));
+	return (ipv6_addr_is_multicast(daddr) ||
+		ipv6_addr_scope_linklocal(daddr));
 }
 
 /*
#8 lore raw

Re: [PATCH 2/4] [IPv6] Add multicast address type inline

In article <[email protected]> (at Thu, 05 Apr 2007 23:21:16 -0400), Brian Haley <[email protected]> says:

Quoted 15 lines

Add multicast address type inline to avoid calls to ipv6_addr_type().

---
  include/net/ipv6.h    |    5 +++++
  net/ipv6/icmp.c       |   12 ++++--------
  net/ipv6/ip6_tunnel.c |    4 ++--
  net/ipv6/route.c      |    4 ++--
  4 files changed, 13 insertions(+), 12 deletions(-)
include/net/ipv6.h +0 -0
index d473789..a888b0e 100644

include/net/ipv6.h static inline int ipv6_addr_scope_sitelocal(const struct in6_addr *a) · line 446

Quoted 8 lines
include/net/ipv6.h +5 -0
@@ -439,6 +439,11 @@ static inline int ipv6_addr_scope_sitelocal(const struct in6_addr *a)
  	return ((a->s6_addr32[0] & htonl(0xFFC00000)) == htonl(0xFEC00000));
  }
 
+static inline int ipv6_addr_type_multicast(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000));
+}
+

Matter of taste, but I prefer ipv6_addr_multicast() to align with ipv6_addr_any().

Quoted 22 lines
net/ipv6/icmp.c +0 -3
index e94992a..709037f 100644
@@ -312,7 +312,6 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
  	struct flowi fl;
  	struct icmpv6_msg msg;
  	int iif = 0;
-	int addr_type = 0;
  	int len;
  	int hlimit, tclass;
  	int err = 0;
@@ -327,8 +326,6 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
  	 *	Rule (e.1) is enforced by not using icmpv6_send
  	 *	in any code that processes icmp errors.
  	 */
-	addr_type = ipv6_addr_type(&hdr->daddr);
-
  	if (ipv6_chk_addr(&hdr->daddr, skb->dev, 0))
  		saddr = &hdr->daddr;
 

net/ipv6/icmp.c void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info, · line 339

Quoted 8 lines
net/ipv6/icmp.c +1 -1
@@ -336,7 +333,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
  	 *	Dest addr check
  	 */
 
-	if ((addr_type & IPV6_ADDR_MULTICAST || skb->pkt_type != PACKET_HOST)) {
+	if (ipv6_addr_type_multicast(&hdr->daddr) || skb->pkt_type != PACKET_HOST) {
  		if (type != ICMPV6_PKT_TOOBIG &&
  		    !(type == ICMPV6_PARAMPROB &&
  		      code == ICMPV6_UNK_OPTION &&

I think this is okay.

Quoted 5 lines
net/ipv6/icmp.c +0 -1
@@ -346,13 +343,11 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
  		saddr = NULL;
  	}
 
-	addr_type = ipv6_addr_type(&hdr->saddr);

net/ipv6/icmp.c void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info, · line 353

Quoted 10 lines
net/ipv6/icmp.c +1 -2
-
  	/*
  	 *	Source addr check
  	 */
 
-	if (addr_type & IPV6_ADDR_LINKLOCAL)
+	if (ipv6_addr_scope_linklocal(&hdr->saddr))
  		iif = skb->dev->ifindex;
 
  	/*

No, this is not identical.

net/ipv6/icmp.c void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info, · line 363

Quoted 10 lines
net/ipv6/icmp.c +2 -1
@@ -361,7 +356,8 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
  	 *	We check unspecified / multicast addresses here,
  	 *	and anycast addresses will be checked later.
  	 */
-	if ((addr_type == IPV6_ADDR_ANY) || (addr_type & IPV6_ADDR_MULTICAST)) {
+	if (ipv6_addr_any(&hdr->saddr) ||
+	    ipv6_addr_type_multicast(&hdr->saddr)) {
  		LIMIT_NETDEBUG(KERN_DEBUG "icmpv6_send: addr_any/mcast source\n");
  		return;
  	}

I guess ipv6_addr_multicast() || ipv6_addr_any() is better.

Quoted 5 lines
net/ipv6/ip6_tunnel.c +0 -0
index a0902fb..0dd1f63 100644

net/ipv6/ip6_tunnel.c static void ip6_tnl_link_config(struct ip6_tnl *t) · line 1118

Quoted 10 lines
net/ipv6/ip6_tunnel.c +2 -2
@@ -1111,8 +1111,8 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
  	dev->iflink = p->link;
 
  	if (p->flags & IP6_TNL_F_CAP_XMIT) {
-		int strict = (ipv6_addr_type(&p->raddr) &
-			      (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
+		int strict = ipv6_addr_type_multicast(&p->raddr) ||
+			     ipv6_addr_scope_linklocal(&p->raddr);
 
  		struct rt6_info *rt = rt6_lookup(&p->raddr, &p->laddr,
  						 p->link, strict);

Different logic, but seems sane.

Quoted 5 lines
net/ipv6/route.c +0 -0
index 53d79ac..32c6398 100644

net/ipv6/route.c static __inline__ int rt6_check_expired(const struct rt6_info *rt) · line 233

Quoted 9 lines
net/ipv6/route.c +2 -2
@@ -227,8 +227,8 @@ static __inline__ int rt6_check_expired(const struct rt6_info *rt)
 
  static inline int rt6_need_strict(struct in6_addr *daddr)
  {
-	return (ipv6_addr_type(daddr) &
-		(IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL));
+	return (ipv6_addr_is_multicast(daddr) ||
+		ipv6_addr_scope_linklocal(daddr));
  }
 

ditto.

--yoshfuji

#9 lore raw

PATCH 3/4 Add mapped address type inline

In reply to a message not in the archive

Add mapped address type inline to avoid calls to ipv6_addr_type().

---
 include/net/ipv6.h       |    6 ++++++
 net/ipv6/ip6_flowlabel.c |    6 ++----
 net/ipv6/ipv6_sockglue.c |    2 +-
 net/ipv6/tcp_ipv6.c      |   13 +++++--------
 net/ipv6/udp.c           |    2 +-
 net/sctp/ipv6.c          |    4 ++--
 6 files changed, 17 insertions(+), 16 deletions(-)
include/net/ipv6.h +6 -0
index a888b0e..f3e13db 100644
@@ -444,6 +444,12 @@ static inline int ipv6_addr_type_multicast(const struct in6_addr *a)
 	return ((a->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000));
 }
 
+static inline int ipv6_addr_type_mapped(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1]) == 0 &&
+		 a->s6_addr32[2] == htonl(0x0000ffff));
+}
+
 /*
  *	Prototypes exported by ipv6
  */
net/ipv6/ip6_flowlabel.c +2 -4
index c206a15..b1bd088 100644
@@ -282,7 +282,6 @@ fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *
 {
 	struct ip6_flowlabel *fl;
 	int olen;
-	int addr_type;
 	int err;
 
 	err = -ENOMEM;
@@ -328,9 +327,8 @@ fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *
 	if (err)
 		goto done;
 	fl->share = freq->flr_share;
-	addr_type = ipv6_addr_type(&freq->flr_dst);
-	if ((addr_type&IPV6_ADDR_MAPPED)
-	    || addr_type == IPV6_ADDR_ANY) {
+	if (ipv6_addr_type_mapped(&freq->flr_dst) ||
+	    ipv6_addr_any(&freq->flr_dst)) {
 		err = -EINVAL;
 		goto done;
 	}
net/ipv6/ipv6_sockglue.c +1 -1
index aa3d07c..d83e982 100644
@@ -249,7 +249,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 			}
 
 			if (ipv6_only_sock(sk) ||
-			    !(ipv6_addr_type(&np->daddr) & IPV6_ADDR_MAPPED)) {
+			    !ipv6_addr_type_mapped(&np->daddr)) {
 				retv = -EADDRNOTAVAIL;
 				break;
 			}
net/ipv6/tcp_ipv6.c +5 -8
index 537978c..a47d23d 100644
@@ -132,7 +132,6 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	struct in6_addr *saddr = NULL, *final_p = NULL, final;
 	struct flowi fl;
 	struct dst_entry *dst;
-	int addr_type;
 	int err;
 
 	if (addr_len < SIN6_LEN_RFC2133)
@@ -163,12 +162,10 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	if(ipv6_addr_any(&usin->sin6_addr))
 		usin->sin6_addr.s6_addr[15] = 0x1;
 
-	addr_type = ipv6_addr_type(&usin->sin6_addr);
-
-	if(addr_type & IPV6_ADDR_MULTICAST)
+	if (ipv6_addr_type_multicast(&usin->sin6_addr))
 		return -ENETUNREACH;
 
-	if (addr_type&IPV6_ADDR_LINKLOCAL) {
+	if (ipv6_addr_scope_linklocal(&usin->sin6_addr)) {
 		if (addr_len >= sizeof(struct sockaddr_in6) &&
 		    usin->sin6_scope_id) {
 			/* If interface is set while binding, indices
@@ -200,7 +197,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	 *	TCP over IPv4
 	 */
 
-	if (addr_type == IPV6_ADDR_MAPPED) {
+	if (ipv6_addr_type_mapped(&usin->sin6_addr)) {
 		u32 exthdrlen = icsk->icsk_ext_hdr_len;
 		struct sockaddr_in sin;
 
@@ -703,7 +703,7 @@ static int tcp_v6_parse_md5_keys (struct sock *sk, char __user *optval,
 	if (!cmd.tcpm_keylen) {
 		if (!tcp_sk(sk)->md5sig_info)
 			return -ENOENT;
-		if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_MAPPED)
+		if (ipv6_addr_type_mapped(&sin6->sin6_addr))
 			return tcp_v4_md5_do_del(sk, sin6->sin6_addr.s6_addr32[3]);
 		return tcp_v6_md5_do_del(sk, &sin6->sin6_addr);
 	}
@@ -725,7 +725,7 @@ static int tcp_v6_parse_md5_keys (struct sock *sk, char __user *optval,
 	newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL);
 	if (!newkey)
 		return -ENOMEM;
-	if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_MAPPED) {
+	if (ipv6_addr_type_mapped(&sin6->sin6_addr)) {
 		return tcp_v4_md5_do_add(sk, sin6->sin6_addr.s6_addr32[3],
 					 newkey, cmd.tcpm_keylen);
 	}
net/ipv6/udp.c +1 -1
index c0b5fe3..6636431 100644
@@ -610,7 +610,7 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
 		daddr = NULL;
 
 	if (daddr) {
-		if (ipv6_addr_type(daddr) == IPV6_ADDR_MAPPED) {
+		if (ipv6_addr_type_mapped(daddr)) {
 			struct sockaddr_in sin;
 			sin.sin_family = AF_INET;
 			sin.sin_port = sin6 ? sin6->sin6_port : inet->dport;
net/sctp/ipv6.c +2 -2
index c1f4a8f..af06d4b 100644
@@ -481,7 +481,7 @@ static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
 	if (addr1->sa.sa_family != addr2->sa.sa_family) {
 		if (addr1->sa.sa_family == AF_INET &&
 		    addr2->sa.sa_family == AF_INET6 &&
-		    IPV6_ADDR_MAPPED == ipv6_addr_type(&addr2->v6.sin6_addr)) {
+		    ipv6_addr_type_mapped(&addr2->v6.sin6_addr)) {
 			if (addr2->v6.sin6_port == addr1->v4.sin_port &&
 			    addr2->v6.sin6_addr.s6_addr32[3] ==
 			    addr1->v4.sin_addr.s_addr)
@@ -489,7 +489,7 @@ static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
 		}
 		if (addr2->sa.sa_family == AF_INET &&
 		    addr1->sa.sa_family == AF_INET6 &&
-		    IPV6_ADDR_MAPPED == ipv6_addr_type(&addr1->v6.sin6_addr)) {
+		    ipv6_addr_type_mapped(&addr1->v6.sin6_addr)) {
 			if (addr1->v6.sin6_port == addr2->v4.sin_port &&
 			    addr1->v6.sin6_addr.s6_addr32[3] ==
 			    addr2->v4.sin_addr.s_addr)
Signature · 1 line
1.5.0.3
#10 lore raw

Re: [PATCH 3/4] Add mapped address type inline

In article <[email protected]> (at Thu, 05 Apr 2007 23:21:25 -0400), Brian Haley <[email protected]> says:

Quoted 19 lines

Add mapped address type inline to avoid calls to ipv6_addr_type().

---
  include/net/ipv6.h       |    6 ++++++
  net/ipv6/ip6_flowlabel.c |    6 ++----
  net/ipv6/ipv6_sockglue.c |    2 +-
  net/ipv6/tcp_ipv6.c      |   13 +++++--------
  net/ipv6/udp.c           |    2 +-
  net/sctp/ipv6.c          |    4 ++--
  6 files changed, 17 insertions(+), 16 deletions(-)
include/net/ipv6.h +0 -0
index a888b0e..f3e13db 100644
@@ -444,6 +444,12 @@ static inline int ipv6_addr_type_multicast(const struct in6_addr *a)
  	return ((a->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000));
  }

include/net/ipv6.h static inline int ipv6_addr_type_multicast(const struct in6_addr *a) · line 455

Quoted 10 lines
include/net/ipv6.h +6 -0
 
+static inline int ipv6_addr_type_mapped(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1]) == 0 &&
+		 a->s6_addr32[2] == htonl(0x0000ffff));
+}
+
  /*
   *	Prototypes exported by ipv6
   */

I prefer ipv6_addr_v4mapped() to align with ipv6_addr_any() (and IN6_IS_ADDR_V4MAPPED() macro in RFC3493).

Quoted 28 lines
net/ipv6/tcp_ipv6.c +2 -5
index 537978c..a47d23d 100644
@@ -132,7 +132,6 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
  	struct in6_addr *saddr = NULL, *final_p = NULL, final;
  	struct flowi fl;
  	struct dst_entry *dst;
-	int addr_type;
  	int err;
 
  	if (addr_len < SIN6_LEN_RFC2133)
@@ -163,12 +162,10 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
  	if(ipv6_addr_any(&usin->sin6_addr))
  		usin->sin6_addr.s6_addr[15] = 0x1;
 
-	addr_type = ipv6_addr_type(&usin->sin6_addr);
-
-	if(addr_type & IPV6_ADDR_MULTICAST)
+	if (ipv6_addr_type_multicast(&usin->sin6_addr))
  		return -ENETUNREACH;
 
-	if (addr_type&IPV6_ADDR_LINKLOCAL) {
+	if (ipv6_addr_scope_linklocal(&usin->sin6_addr)) {
  		if (addr_len >= sizeof(struct sockaddr_in6) &&
  		    usin->sin6_scope_id) {
  			/* If interface is set while binding, indices

net/ipv6/tcp_ipv6.c static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, · line 198

Quoted 2 lines
net/ipv6/tcp_ipv6.c +0 -0
@@ -200,7 +197,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
  	 *	TCP over IPv4
  	 */

different commit?

--yoshfuji

#11 lore raw

PATCH 4/4 Add loopback address type inline

In reply to a message not in the archive

Add loopback address type inline to avoid calls to ipv6_addr_type().

---
 include/net/ipv6.h    |    7 +++++++
 net/ipv6/ip6_output.c |    5 +++--
 net/ipv6/route.c      |    8 +++-----
 3 files changed, 13 insertions(+), 7 deletions(-)
include/net/ipv6.h +7 -0
index f3e13db..d87f421 100644
@@ -388,6 +388,13 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0);
 }
 
+static inline int ipv6_addr_loopback(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1] |
+		 a->s6_addr32[2] ) == 0 &&
+		 a->s6_addr32[3] == htonl(0x00000001));
+}
+
 /*
  * find the first different bit between two addresses
  * length of address must be a multiple of 32bits
net/ipv6/ip6_output.c +3 -2
index f6aa338..7f1aabe 100644
@@ -455,8 +455,9 @@ int ip6_forward(struct sk_buff *skb)
 		 */
 		if (xrlim_allow(dst, 1*HZ))
 			ndisc_send_redirect(skb, n, target);
-	} else if (ipv6_addr_type(&hdr->saddr)&(IPV6_ADDR_MULTICAST|IPV6_ADDR_LOOPBACK
-						|IPV6_ADDR_LINKLOCAL)) {
+	} else if (ipv6_addr_type_multicast(&hdr->saddr) ||
+		   ipv6_addr_loopback(&hdr->saddr) ||
+		   ipv6_addr_scope_linklocal(&hdr->saddr)) {
 		/* This check is security critical. */
 		goto error;
 	}
net/ipv6/route.c +3 -5
index 32c6398..06ee92d 100644
@@ -1067,7 +1067,6 @@ int ip6_route_add(struct fib6_config *cfg)
 	struct net_device *dev = NULL;
 	struct inet6_dev *idev = NULL;
 	struct fib6_table *table;
-	int addr_type;
 
 	if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
 		return -EINVAL;
@@ -1108,9 +1107,7 @@ int ip6_route_add(struct fib6_config *cfg)
 		cfg->fc_protocol = RTPROT_BOOT;
 	rt->rt6i_protocol = cfg->fc_protocol;
 
-	addr_type = ipv6_addr_type(&cfg->fc_dst);
-
-	if (addr_type & IPV6_ADDR_MULTICAST)
+	if (ipv6_addr_type_multicast(&cfg->fc_dst))
 		rt->u.dst.input = ip6_mc_input;
 	else
 		rt->u.dst.input = ip6_forward;
@@ -1133,7 +1130,8 @@ int ip6_route_add(struct fib6_config *cfg)
 	   they would result in kernel looping; promote them to reject routes
 	 */
 	if ((cfg->fc_flags & RTF_REJECT) ||
-	    (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) {
+	    (dev && (dev->flags&IFF_LOOPBACK) &&
+	     !ipv6_addr_loopback(&cfg->fc_dst))) {
 		/* hold loopback dev/idev if we haven't done so. */
 		if (dev != &loopback_dev) {
 			if (dev) {
Signature · 1 line
1.5.0.3
#12 lore raw

Re: [PATCH 4/4] Add loopback address type inline

In article <[email protected]> (at Thu, 05 Apr 2007 23:21:33 -0400), Brian Haley <[email protected]> says:

Quoted 31 lines

Add loopback address type inline to avoid calls to ipv6_addr_type().

net/ipv6/ip6_output.c +3 -2
index f6aa338..7f1aabe 100644
@@ -455,8 +455,9 @@ int ip6_forward(struct sk_buff *skb)
  		 */
  		if (xrlim_allow(dst, 1*HZ))
  			ndisc_send_redirect(skb, n, target);
-	} else if (ipv6_addr_type(&hdr->saddr)&(IPV6_ADDR_MULTICAST|IPV6_ADDR_LOOPBACK
-						|IPV6_ADDR_LINKLOCAL)) {
+	} else if (ipv6_addr_type_multicast(&hdr->saddr) ||
+		   ipv6_addr_loopback(&hdr->saddr) ||
+		   ipv6_addr_scope_linklocal(&hdr->saddr)) {
  		/* This check is security critical. */
  		goto error;
  	}
net/ipv6/route.c +0 -1
index 32c6398..06ee92d 100644
@@ -1067,7 +1067,6 @@ int ip6_route_add(struct fib6_config *cfg)
  	struct net_device *dev = NULL;
  	struct inet6_dev *idev = NULL;
  	struct fib6_table *table;
-	int addr_type;
 
  	if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
  		return -EINVAL;

net/ipv6/route.c int ip6_route_add(struct fib6_config *cfg) · line 1113

Quoted 10 lines
net/ipv6/route.c +1 -3
@@ -1108,9 +1107,7 @@ int ip6_route_add(struct fib6_config *cfg)
  		cfg->fc_protocol = RTPROT_BOOT;
  	rt->rt6i_protocol = cfg->fc_protocol;
 
-	addr_type = ipv6_addr_type(&cfg->fc_dst);
-
-	if (addr_type & IPV6_ADDR_MULTICAST)
+	if (ipv6_addr_type_multicast(&cfg->fc_dst))
  		rt->u.dst.input = ip6_mc_input;
  	else
  		rt->u.dst.input = ip6_forward;

different commit...

--yoshfuji

#13 lore raw

Re: [PATCH 4/4] Add loopback address type inline

Quoted 16 lines · YOSHIFUJI Hideaki / ????
Quoted 16 lines
net/ipv6/route.c +0 -1
index 32c6398..06ee92d 100644
@@ -1067,7 +1067,6 @@ int ip6_route_add(struct fib6_config *cfg)
  	struct net_device *dev = NULL;
  	struct inet6_dev *idev = NULL;
  	struct fib6_table *table;
-	int addr_type;
 
  	if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
  		return -EINVAL;
@@ -1108,9 +1107,7 @@ int ip6_route_add(struct fib6_config *cfg)
  		cfg->fc_protocol = RTPROT_BOOT;
  	rt->rt6i_protocol = cfg->fc_protocol;
 
Quoted 9 lines

net/ipv6/route.c int ip6_route_add(struct fib6_config *cfg) · line 1113

Quoted 7 lines
net/ipv6/route.c +1 -3
-	addr_type = ipv6_addr_type(&cfg->fc_dst);
-
-	if (addr_type & IPV6_ADDR_MULTICAST)
+	if (ipv6_addr_type_multicast(&cfg->fc_dst))
  		rt->u.dst.input = ip6_mc_input;
  	else
  		rt->u.dst.input = ip6_forward;

different commit...

This and the previous patch were layered, and I couldn't add the rest of this change without the loopback inline:

net/ipv6/route.c int ip6_route_add(struct fib6_config *cfg) · line 1137

Quoted 10 lines
net/ipv6/route.c +2 -1
@@ -1133,7 +1130,8 @@ int ip6_route_add(struct fib6_config *cfg)
 	   they would result in kernel looping; promote them to reject routes
 	 */
 	if ((cfg->fc_flags & RTF_REJECT) ||
-	    (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) {
+	    (dev && (dev->flags&IFF_LOOPBACK) &&
+	     !ipv6_addr_loopback(&cfg->fc_dst))) {
 		/* hold loopback dev/idev if we haven't done so. */
 		if (dev != &loopback_dev) {
 			if (dev) {

because they both used addr_type.

I'll put this all in one patch together next time so it's more obvious.

-Brian