Commit 4b048d6d authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

net: Change pseudohdr argument of inet_proto_csum_replace* to be a bool

inet_proto_csum_replace4,2,16 take a pseudohdr argument which indicates
the checksum field carries a pseudo header. This argument should be a
boolean instead of an int.
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 25368623
...@@ -140,14 +140,14 @@ static inline void csum_replace2(__sum16 *sum, __be16 old, __be16 new) ...@@ -140,14 +140,14 @@ static inline void csum_replace2(__sum16 *sum, __be16 old, __be16 new)
struct sk_buff; struct sk_buff;
void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
__be32 from, __be32 to, int pseudohdr); __be32 from, __be32 to, bool pseudohdr);
void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb, void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
const __be32 *from, const __be32 *to, const __be32 *from, const __be32 *to,
int pseudohdr); bool pseudohdr);
static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb, static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
__be16 from, __be16 to, __be16 from, __be16 to,
int pseudohdr) bool pseudohdr)
{ {
inet_proto_csum_replace4(sum, skb, (__force __be32)from, inet_proto_csum_replace4(sum, skb, (__force __be32)from,
(__force __be32)to, pseudohdr); (__force __be32)to, pseudohdr);
......
...@@ -1349,7 +1349,7 @@ const struct bpf_func_proto bpf_l3_csum_replace_proto = { ...@@ -1349,7 +1349,7 @@ const struct bpf_func_proto bpf_l3_csum_replace_proto = {
static u64 bpf_l4_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags) static u64 bpf_l4_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags)
{ {
struct sk_buff *skb = (struct sk_buff *) (long) r1; struct sk_buff *skb = (struct sk_buff *) (long) r1;
u32 is_pseudo = BPF_IS_PSEUDO_HEADER(flags); bool is_pseudo = !!BPF_IS_PSEUDO_HEADER(flags);
int offset = (int) r2; int offset = (int) r2;
__sum16 sum, *ptr; __sum16 sum, *ptr;
......
...@@ -301,7 +301,7 @@ int in6_pton(const char *src, int srclen, ...@@ -301,7 +301,7 @@ int in6_pton(const char *src, int srclen,
EXPORT_SYMBOL(in6_pton); EXPORT_SYMBOL(in6_pton);
void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
__be32 from, __be32 to, int pseudohdr) __be32 from, __be32 to, bool pseudohdr)
{ {
if (skb->ip_summed != CHECKSUM_PARTIAL) { if (skb->ip_summed != CHECKSUM_PARTIAL) {
csum_replace4(sum, from, to); csum_replace4(sum, from, to);
...@@ -318,7 +318,7 @@ EXPORT_SYMBOL(inet_proto_csum_replace4); ...@@ -318,7 +318,7 @@ EXPORT_SYMBOL(inet_proto_csum_replace4);
void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb, void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
const __be32 *from, const __be32 *to, const __be32 *from, const __be32 *to,
int pseudohdr) bool pseudohdr)
{ {
__be32 diff[] = { __be32 diff[] = {
~from[0], ~from[1], ~from[2], ~from[3], ~from[0], ~from[1], ~from[2], ~from[3],
......
...@@ -72,7 +72,7 @@ set_ect_tcp(struct sk_buff *skb, const struct ipt_ECN_info *einfo) ...@@ -72,7 +72,7 @@ set_ect_tcp(struct sk_buff *skb, const struct ipt_ECN_info *einfo)
tcph->cwr = einfo->proto.tcp.cwr; tcph->cwr = einfo->proto.tcp.cwr;
inet_proto_csum_replace2(&tcph->check, skb, inet_proto_csum_replace2(&tcph->check, skb,
oldval, ((__be16 *)tcph)[6], 0); oldval, ((__be16 *)tcph)[6], false);
return true; return true;
} }
......
...@@ -120,7 +120,7 @@ static void nf_nat_ipv4_csum_update(struct sk_buff *skb, ...@@ -120,7 +120,7 @@ static void nf_nat_ipv4_csum_update(struct sk_buff *skb,
oldip = iph->daddr; oldip = iph->daddr;
newip = t->dst.u3.ip; newip = t->dst.u3.ip;
} }
inet_proto_csum_replace4(check, skb, oldip, newip, 1); inet_proto_csum_replace4(check, skb, oldip, newip, true);
} }
static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb, static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb,
...@@ -151,7 +151,7 @@ static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb, ...@@ -151,7 +151,7 @@ static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb,
} }
} else } else
inet_proto_csum_replace2(check, skb, inet_proto_csum_replace2(check, skb,
htons(oldlen), htons(datalen), 1); htons(oldlen), htons(datalen), true);
} }
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
......
...@@ -67,7 +67,7 @@ icmp_manip_pkt(struct sk_buff *skb, ...@@ -67,7 +67,7 @@ icmp_manip_pkt(struct sk_buff *skb,
hdr = (struct icmphdr *)(skb->data + hdroff); hdr = (struct icmphdr *)(skb->data + hdroff);
inet_proto_csum_replace2(&hdr->checksum, skb, inet_proto_csum_replace2(&hdr->checksum, skb,
hdr->un.echo.id, tuple->src.u.icmp.id, 0); hdr->un.echo.id, tuple->src.u.icmp.id, false);
hdr->un.echo.id = tuple->src.u.icmp.id; hdr->un.echo.id = tuple->src.u.icmp.id;
return true; return true;
} }
......
...@@ -124,7 +124,7 @@ static void nf_nat_ipv6_csum_update(struct sk_buff *skb, ...@@ -124,7 +124,7 @@ static void nf_nat_ipv6_csum_update(struct sk_buff *skb,
newip = &t->dst.u3.in6; newip = &t->dst.u3.in6;
} }
inet_proto_csum_replace16(check, skb, oldip->s6_addr32, inet_proto_csum_replace16(check, skb, oldip->s6_addr32,
newip->s6_addr32, 1); newip->s6_addr32, true);
} }
static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb, static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb,
...@@ -155,7 +155,7 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb, ...@@ -155,7 +155,7 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb,
} }
} else } else
inet_proto_csum_replace2(check, skb, inet_proto_csum_replace2(check, skb,
htons(oldlen), htons(datalen), 1); htons(oldlen), htons(datalen), true);
} }
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
......
...@@ -73,7 +73,7 @@ icmpv6_manip_pkt(struct sk_buff *skb, ...@@ -73,7 +73,7 @@ icmpv6_manip_pkt(struct sk_buff *skb,
hdr->icmp6_type == ICMPV6_ECHO_REPLY) { hdr->icmp6_type == ICMPV6_ECHO_REPLY) {
inet_proto_csum_replace2(&hdr->icmp6_cksum, skb, inet_proto_csum_replace2(&hdr->icmp6_cksum, skb,
hdr->icmp6_identifier, hdr->icmp6_identifier,
tuple->src.u.icmp.id, 0); tuple->src.u.icmp.id, false);
hdr->icmp6_identifier = tuple->src.u.icmp.id; hdr->icmp6_identifier = tuple->src.u.icmp.id;
} }
return true; return true;
......
...@@ -103,9 +103,9 @@ static void nf_ct_sack_block_adjust(struct sk_buff *skb, ...@@ -103,9 +103,9 @@ static void nf_ct_sack_block_adjust(struct sk_buff *skb,
ntohl(sack->end_seq), ntohl(new_end_seq)); ntohl(sack->end_seq), ntohl(new_end_seq));
inet_proto_csum_replace4(&tcph->check, skb, inet_proto_csum_replace4(&tcph->check, skb,
sack->start_seq, new_start_seq, 0); sack->start_seq, new_start_seq, false);
inet_proto_csum_replace4(&tcph->check, skb, inet_proto_csum_replace4(&tcph->check, skb,
sack->end_seq, new_end_seq, 0); sack->end_seq, new_end_seq, false);
sack->start_seq = new_start_seq; sack->start_seq = new_start_seq;
sack->end_seq = new_end_seq; sack->end_seq = new_end_seq;
sackoff += sizeof(*sack); sackoff += sizeof(*sack);
...@@ -193,8 +193,9 @@ int nf_ct_seq_adjust(struct sk_buff *skb, ...@@ -193,8 +193,9 @@ int nf_ct_seq_adjust(struct sk_buff *skb,
newseq = htonl(ntohl(tcph->seq) + seqoff); newseq = htonl(ntohl(tcph->seq) + seqoff);
newack = htonl(ntohl(tcph->ack_seq) - ackoff); newack = htonl(ntohl(tcph->ack_seq) - ackoff);
inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, 0); inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, false);
inet_proto_csum_replace4(&tcph->check, skb, tcph->ack_seq, newack, 0); inet_proto_csum_replace4(&tcph->check, skb, tcph->ack_seq, newack,
false);
pr_debug("Adjusting sequence number from %u->%u, ack from %u->%u\n", pr_debug("Adjusting sequence number from %u->%u, ack from %u->%u\n",
ntohl(tcph->seq), ntohl(newseq), ntohl(tcph->ack_seq), ntohl(tcph->seq), ntohl(newseq), ntohl(tcph->ack_seq),
......
...@@ -69,7 +69,7 @@ dccp_manip_pkt(struct sk_buff *skb, ...@@ -69,7 +69,7 @@ dccp_manip_pkt(struct sk_buff *skb,
l3proto->csum_update(skb, iphdroff, &hdr->dccph_checksum, l3proto->csum_update(skb, iphdroff, &hdr->dccph_checksum,
tuple, maniptype); tuple, maniptype);
inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport, inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport,
0); false);
return true; return true;
} }
......
...@@ -70,7 +70,7 @@ tcp_manip_pkt(struct sk_buff *skb, ...@@ -70,7 +70,7 @@ tcp_manip_pkt(struct sk_buff *skb,
return true; return true;
l3proto->csum_update(skb, iphdroff, &hdr->check, tuple, maniptype); l3proto->csum_update(skb, iphdroff, &hdr->check, tuple, maniptype);
inet_proto_csum_replace2(&hdr->check, skb, oldport, newport, 0); inet_proto_csum_replace2(&hdr->check, skb, oldport, newport, false);
return true; return true;
} }
......
...@@ -57,7 +57,7 @@ udp_manip_pkt(struct sk_buff *skb, ...@@ -57,7 +57,7 @@ udp_manip_pkt(struct sk_buff *skb,
l3proto->csum_update(skb, iphdroff, &hdr->check, l3proto->csum_update(skb, iphdroff, &hdr->check,
tuple, maniptype); tuple, maniptype);
inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport,
0); false);
if (!hdr->check) if (!hdr->check)
hdr->check = CSUM_MANGLED_0; hdr->check = CSUM_MANGLED_0;
} }
......
...@@ -56,7 +56,7 @@ udplite_manip_pkt(struct sk_buff *skb, ...@@ -56,7 +56,7 @@ udplite_manip_pkt(struct sk_buff *skb,
} }
l3proto->csum_update(skb, iphdroff, &hdr->check, tuple, maniptype); l3proto->csum_update(skb, iphdroff, &hdr->check, tuple, maniptype);
inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, 0); inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, false);
if (!hdr->check) if (!hdr->check)
hdr->check = CSUM_MANGLED_0; hdr->check = CSUM_MANGLED_0;
......
...@@ -225,7 +225,7 @@ unsigned int synproxy_tstamp_adjust(struct sk_buff *skb, ...@@ -225,7 +225,7 @@ unsigned int synproxy_tstamp_adjust(struct sk_buff *skb,
synproxy->tsoff); synproxy->tsoff);
} }
inet_proto_csum_replace4(&th->check, skb, inet_proto_csum_replace4(&th->check, skb,
old, *ptr, 0); old, *ptr, false);
return 1; return 1;
} }
optoff += op[1]; optoff += op[1];
......
...@@ -144,7 +144,7 @@ tcpmss_mangle_packet(struct sk_buff *skb, ...@@ -144,7 +144,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,
inet_proto_csum_replace2(&tcph->check, skb, inet_proto_csum_replace2(&tcph->check, skb,
htons(oldmss), htons(newmss), htons(oldmss), htons(newmss),
0); false);
return 0; return 0;
} }
} }
...@@ -185,18 +185,18 @@ tcpmss_mangle_packet(struct sk_buff *skb, ...@@ -185,18 +185,18 @@ tcpmss_mangle_packet(struct sk_buff *skb,
memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr)); memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr));
inet_proto_csum_replace2(&tcph->check, skb, inet_proto_csum_replace2(&tcph->check, skb,
htons(len), htons(len + TCPOLEN_MSS), 1); htons(len), htons(len + TCPOLEN_MSS), true);
opt[0] = TCPOPT_MSS; opt[0] = TCPOPT_MSS;
opt[1] = TCPOLEN_MSS; opt[1] = TCPOLEN_MSS;
opt[2] = (newmss & 0xff00) >> 8; opt[2] = (newmss & 0xff00) >> 8;
opt[3] = newmss & 0x00ff; opt[3] = newmss & 0x00ff;
inet_proto_csum_replace4(&tcph->check, skb, 0, *((__be32 *)opt), 0); inet_proto_csum_replace4(&tcph->check, skb, 0, *((__be32 *)opt), false);
oldval = ((__be16 *)tcph)[6]; oldval = ((__be16 *)tcph)[6];
tcph->doff += TCPOLEN_MSS/4; tcph->doff += TCPOLEN_MSS/4;
inet_proto_csum_replace2(&tcph->check, skb, inet_proto_csum_replace2(&tcph->check, skb,
oldval, ((__be16 *)tcph)[6], 0); oldval, ((__be16 *)tcph)[6], false);
return TCPOLEN_MSS; return TCPOLEN_MSS;
} }
......
...@@ -80,7 +80,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb, ...@@ -80,7 +80,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
n <<= 8; n <<= 8;
} }
inet_proto_csum_replace2(&tcph->check, skb, htons(o), inet_proto_csum_replace2(&tcph->check, skb, htons(o),
htons(n), 0); htons(n), false);
} }
memset(opt + i, TCPOPT_NOP, optl); memset(opt + i, TCPOPT_NOP, optl);
} }
......
...@@ -284,14 +284,14 @@ static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh, ...@@ -284,14 +284,14 @@ static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
if (nh->protocol == IPPROTO_TCP) { if (nh->protocol == IPPROTO_TCP) {
if (likely(transport_len >= sizeof(struct tcphdr))) if (likely(transport_len >= sizeof(struct tcphdr)))
inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb, inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
addr, new_addr, 1); addr, new_addr, true);
} else if (nh->protocol == IPPROTO_UDP) { } else if (nh->protocol == IPPROTO_UDP) {
if (likely(transport_len >= sizeof(struct udphdr))) { if (likely(transport_len >= sizeof(struct udphdr))) {
struct udphdr *uh = udp_hdr(skb); struct udphdr *uh = udp_hdr(skb);
if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace4(&uh->check, skb, inet_proto_csum_replace4(&uh->check, skb,
addr, new_addr, 1); addr, new_addr, true);
if (!uh->check) if (!uh->check)
uh->check = CSUM_MANGLED_0; uh->check = CSUM_MANGLED_0;
} }
...@@ -316,14 +316,14 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto, ...@@ -316,14 +316,14 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
if (l4_proto == NEXTHDR_TCP) { if (l4_proto == NEXTHDR_TCP) {
if (likely(transport_len >= sizeof(struct tcphdr))) if (likely(transport_len >= sizeof(struct tcphdr)))
inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb, inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
addr, new_addr, 1); addr, new_addr, true);
} else if (l4_proto == NEXTHDR_UDP) { } else if (l4_proto == NEXTHDR_UDP) {
if (likely(transport_len >= sizeof(struct udphdr))) { if (likely(transport_len >= sizeof(struct udphdr))) {
struct udphdr *uh = udp_hdr(skb); struct udphdr *uh = udp_hdr(skb);
if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace16(&uh->check, skb, inet_proto_csum_replace16(&uh->check, skb,
addr, new_addr, 1); addr, new_addr, true);
if (!uh->check) if (!uh->check)
uh->check = CSUM_MANGLED_0; uh->check = CSUM_MANGLED_0;
} }
...@@ -331,7 +331,7 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto, ...@@ -331,7 +331,7 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
} else if (l4_proto == NEXTHDR_ICMP) { } else if (l4_proto == NEXTHDR_ICMP) {
if (likely(transport_len >= sizeof(struct icmp6hdr))) if (likely(transport_len >= sizeof(struct icmp6hdr)))
inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum, inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
skb, addr, new_addr, 1); skb, addr, new_addr, true);
} }
} }
...@@ -498,7 +498,7 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, ...@@ -498,7 +498,7 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,
static void set_tp_port(struct sk_buff *skb, __be16 *port, static void set_tp_port(struct sk_buff *skb, __be16 *port,
__be16 new_port, __sum16 *check) __be16 new_port, __sum16 *check)
{ {
inet_proto_csum_replace2(check, skb, *port, new_port, 0); inet_proto_csum_replace2(check, skb, *port, new_port, false);
*port = new_port; *port = new_port;
} }
......
...@@ -162,7 +162,8 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a, ...@@ -162,7 +162,8 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a,
goto drop; goto drop;
tcph = (void *)(skb_network_header(skb) + ihl); tcph = (void *)(skb_network_header(skb) + ihl);
inet_proto_csum_replace4(&tcph->check, skb, addr, new_addr, 1); inet_proto_csum_replace4(&tcph->check, skb, addr, new_addr,
true);
break; break;
} }
case IPPROTO_UDP: case IPPROTO_UDP:
...@@ -178,7 +179,7 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a, ...@@ -178,7 +179,7 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a,
udph = (void *)(skb_network_header(skb) + ihl); udph = (void *)(skb_network_header(skb) + ihl);
if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) { if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace4(&udph->check, skb, addr, inet_proto_csum_replace4(&udph->check, skb, addr,
new_addr, 1); new_addr, true);
if (!udph->check) if (!udph->check)
udph->check = CSUM_MANGLED_0; udph->check = CSUM_MANGLED_0;
} }
...@@ -231,7 +232,7 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a, ...@@ -231,7 +232,7 @@ static int tcf_nat(struct sk_buff *skb, const struct tc_action *a,
iph->saddr = new_addr; iph->saddr = new_addr;
inet_proto_csum_replace4(&icmph->checksum, skb, addr, new_addr, inet_proto_csum_replace4(&icmph->checksum, skb, addr, new_addr,
0); false);
break; break;
} }
default: default:
......
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