[IPV6] MIP6: Several obvious clean-ups.
- Remove redundant code. Pointed out by Brian Haley <brian.haley@hp.com>. - Unify code paths with/without CONFIG_IPV6_MIP. - Use NIP6_FMT for IPv6 address textual presentation. - Fold long line. Pointed out by David Miller <davem@davemloft.net>. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
This commit is contained in:
parent
e4bec827fe
commit
e731c248ba
|
@ -128,9 +128,7 @@ static void ipv6_rearrange_destopt(struct ipv6hdr *iph, struct ipv6_opt_hdr *des
|
||||||
off += optlen;
|
off += optlen;
|
||||||
len -= optlen;
|
len -= optlen;
|
||||||
}
|
}
|
||||||
if (len == 0)
|
/* Note: ok if len == 0 */
|
||||||
return;
|
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -175,11 +173,7 @@ static void ipv6_rearrange_rthdr(struct ipv6hdr *iph, struct ipv6_rt_hdr *rthdr)
|
||||||
ipv6_addr_copy(&iph->daddr, &final_addr);
|
ipv6_addr_copy(&iph->daddr, &final_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_IPV6_MIP6
|
|
||||||
static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len, int dir)
|
static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len, int dir)
|
||||||
#else
|
|
||||||
static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
struct ipv6hdr *iph;
|
struct ipv6hdr *iph;
|
||||||
|
@ -194,39 +188,20 @@ static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len)
|
||||||
|
|
||||||
while (exthdr.raw < end) {
|
while (exthdr.raw < end) {
|
||||||
switch (nexthdr) {
|
switch (nexthdr) {
|
||||||
#ifdef CONFIG_IPV6_MIP6
|
|
||||||
case NEXTHDR_HOP:
|
|
||||||
if (!zero_out_mutable_opts(exthdr.opth)) {
|
|
||||||
LIMIT_NETDEBUG(
|
|
||||||
KERN_WARNING "overrun %sopts\n",
|
|
||||||
nexthdr == NEXTHDR_HOP ?
|
|
||||||
"hop" : "dest");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NEXTHDR_DEST:
|
case NEXTHDR_DEST:
|
||||||
|
#ifdef CONFIG_IPV6_MIP6
|
||||||
if (dir == XFRM_POLICY_OUT)
|
if (dir == XFRM_POLICY_OUT)
|
||||||
ipv6_rearrange_destopt(iph, exthdr.opth);
|
ipv6_rearrange_destopt(iph, exthdr.opth);
|
||||||
if (!zero_out_mutable_opts(exthdr.opth)) {
|
|
||||||
LIMIT_NETDEBUG(
|
|
||||||
KERN_WARNING "overrun %sopts\n",
|
|
||||||
nexthdr == NEXTHDR_HOP ?
|
|
||||||
"hop" : "dest");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#else
|
|
||||||
case NEXTHDR_HOP:
|
|
||||||
case NEXTHDR_DEST:
|
|
||||||
if (!zero_out_mutable_opts(exthdr.opth)) {
|
|
||||||
LIMIT_NETDEBUG(
|
|
||||||
KERN_WARNING "overrun %sopts\n",
|
|
||||||
nexthdr == NEXTHDR_HOP ?
|
|
||||||
"hop" : "dest");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
case NEXTHDR_HOP:
|
||||||
|
if (!zero_out_mutable_opts(exthdr.opth)) {
|
||||||
|
LIMIT_NETDEBUG(
|
||||||
|
KERN_WARNING "overrun %sopts\n",
|
||||||
|
nexthdr == NEXTHDR_HOP ?
|
||||||
|
"hop" : "dest");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case NEXTHDR_ROUTING:
|
case NEXTHDR_ROUTING:
|
||||||
ipv6_rearrange_rthdr(iph, exthdr.rth);
|
ipv6_rearrange_rthdr(iph, exthdr.rth);
|
||||||
|
@ -282,16 +257,13 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_IPV6_MIP6
|
#ifdef CONFIG_IPV6_MIP6
|
||||||
memcpy(tmp_ext, &top_iph->saddr, extlen);
|
memcpy(tmp_ext, &top_iph->saddr, extlen);
|
||||||
|
#else
|
||||||
|
memcpy(tmp_ext, &top_iph->daddr, extlen);
|
||||||
|
#endif
|
||||||
err = ipv6_clear_mutable_options(top_iph,
|
err = ipv6_clear_mutable_options(top_iph,
|
||||||
extlen - sizeof(*tmp_ext) +
|
extlen - sizeof(*tmp_ext) +
|
||||||
sizeof(*top_iph),
|
sizeof(*top_iph),
|
||||||
XFRM_POLICY_OUT);
|
XFRM_POLICY_OUT);
|
||||||
#else
|
|
||||||
memcpy(tmp_ext, &top_iph->daddr, extlen);
|
|
||||||
err = ipv6_clear_mutable_options(top_iph,
|
|
||||||
extlen - sizeof(*tmp_ext) +
|
|
||||||
sizeof(*top_iph));
|
|
||||||
#endif
|
|
||||||
if (err)
|
if (err)
|
||||||
goto error_free_iph;
|
goto error_free_iph;
|
||||||
}
|
}
|
||||||
|
@ -386,13 +358,8 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||||
if (!tmp_hdr)
|
if (!tmp_hdr)
|
||||||
goto out;
|
goto out;
|
||||||
memcpy(tmp_hdr, skb->nh.raw, hdr_len);
|
memcpy(tmp_hdr, skb->nh.raw, hdr_len);
|
||||||
#ifdef CONFIG_IPV6_MIP6
|
|
||||||
if (ipv6_clear_mutable_options(skb->nh.ipv6h, hdr_len, XFRM_POLICY_IN))
|
if (ipv6_clear_mutable_options(skb->nh.ipv6h, hdr_len, XFRM_POLICY_IN))
|
||||||
goto free_out;
|
goto free_out;
|
||||||
#else
|
|
||||||
if (ipv6_clear_mutable_options(skb->nh.ipv6h, hdr_len))
|
|
||||||
goto free_out;
|
|
||||||
#endif
|
|
||||||
skb->nh.ipv6h->priority = 0;
|
skb->nh.ipv6h->priority = 0;
|
||||||
skb->nh.ipv6h->flow_lbl[0] = 0;
|
skb->nh.ipv6h->flow_lbl[0] = 0;
|
||||||
skb->nh.ipv6h->flow_lbl[1] = 0;
|
skb->nh.ipv6h->flow_lbl[1] = 0;
|
||||||
|
|
|
@ -87,7 +87,6 @@ int ipv6_find_tlv(struct sk_buff *skb, int offset, int type)
|
||||||
len -= optlen;
|
len -= optlen;
|
||||||
}
|
}
|
||||||
/* not_found */
|
/* not_found */
|
||||||
return -1;
|
|
||||||
bad:
|
bad:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,8 @@ int mip6_mh_filter(struct sock *sk, struct sk_buff *skb)
|
||||||
&skb->nh.ipv6h->daddr,
|
&skb->nh.ipv6h->daddr,
|
||||||
mhlen, IPPROTO_MH,
|
mhlen, IPPROTO_MH,
|
||||||
skb_checksum(skb, 0, mhlen, 0))) {
|
skb_checksum(skb, 0, mhlen, 0))) {
|
||||||
LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH checksum failed [%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x > %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]\n",
|
LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH checksum failed "
|
||||||
|
"[" NIP6_FMT " > " NIP6_FMT "]\n",
|
||||||
NIP6(skb->nh.ipv6h->saddr),
|
NIP6(skb->nh.ipv6h->saddr),
|
||||||
NIP6(skb->nh.ipv6h->daddr));
|
NIP6(skb->nh.ipv6h->daddr));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -234,7 +235,8 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, struct
|
||||||
struct timeval stamp;
|
struct timeval stamp;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (unlikely(fl->proto == IPPROTO_MH && fl->fl_mh_type <= IP6_MH_TYPE_MAX))
|
if (unlikely(fl->proto == IPPROTO_MH &&
|
||||||
|
fl->fl_mh_type <= IP6_MH_TYPE_MAX))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (likely(opt->dsthao)) {
|
if (likely(opt->dsthao)) {
|
||||||
|
|
Loading…
Reference in New Issue