Skip to content

Commit

Permalink
ipv6: Use ipv6_authlen for len
Browse files Browse the repository at this point in the history
The length of AH header is computed manually as (hp->hdrlen+2)<<2.
However, in include/linux/ipv6.h, a macro named ipv6_authlen is
already defined for exactly the same job. This commit replaces
the manual computation code with the macro.

Signed-off-by: yangxingwu <xingwu.yang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
yangxingwu authored and David S. Miller committed Jul 11, 2019
1 parent 311633b commit 416e812
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions net/ipv6/ah6.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static void ah6_input_done(struct crypto_async_request *base, int err)
struct ah_data *ahp = x->data;
struct ip_auth_hdr *ah = ip_auth_hdr(skb);
int hdr_len = skb_network_header_len(skb);
int ah_hlen = (ah->hdrlen + 2) << 2;
int ah_hlen = ipv6_authlen(ah);

if (err)
goto out;
Expand Down Expand Up @@ -546,7 +546,7 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
ahash = ahp->ahash;

nexthdr = ah->nexthdr;
ah_hlen = (ah->hdrlen + 2) << 2;
ah_hlen = ipv6_authlen(ah);

if (ah_hlen != XFRM_ALIGN8(sizeof(*ah) + ahp->icv_full_len) &&
ah_hlen != XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len))
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/exthdrs_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
} else if (nexthdr == NEXTHDR_AUTH) {
if (flags && (*flags & IP6_FH_F_AUTH) && (target < 0))
break;
hdrlen = (hp->hdrlen + 2) << 2;
hdrlen = ipv6_authlen(hp);
} else
hdrlen = ipv6_optlen(hp);

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw)
break;
optlen = 8;
} else if (nexthdr == NEXTHDR_AUTH) {
optlen = (hdr->hdrlen + 2) << 2;
optlen = ipv6_authlen(hdr);
} else {
optlen = ipv6_optlen(hdr);
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6t_ah.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par)
return false;
}

hdrlen = (ah->hdrlen + 2) << 2;
hdrlen = ipv6_authlen(ah);

pr_debug("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
pr_debug("RES %04X ", ah->reserved);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6t_ipv6header.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ipv6header_mt6(const struct sk_buff *skb, struct xt_action_param *par)
if (nexthdr == NEXTHDR_FRAGMENT)
hdrlen = 8;
else if (nexthdr == NEXTHDR_AUTH)
hdrlen = (hp->hdrlen + 2) << 2;
hdrlen = ipv6_authlen(hp);
else
hdrlen = ipv6_optlen(hp);

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/nf_conntrack_reasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
BUG();
if (nexthdr == NEXTHDR_AUTH)
hdrlen = (hdr.hdrlen+2)<<2;
hdrlen = ipv6_authlen(&hdr);
else
hdrlen = ipv6_optlen(&hdr);

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/nf_log_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void dump_ipv6_packet(struct net *net, struct nf_log_buf *m,

}

hdrlen = (hp->hdrlen+2)<<2;
hdrlen = ipv6_authlen(hp);
break;
case IPPROTO_ESP:
if (logflags & NF_LOG_IPOPT) {
Expand Down

0 comments on commit 416e812

Please sign in to comment.