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

flow_dissector: Jump to exit code in __skb_flow_dissect

Instead of returning immediately (on a parsing failure for instance) we
jump to cleanup code. This always sets protocol values in key_control
(even on a failure there is still valid information in the key_tags that
was set before the problem was hit).
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c6cc1ca7
...@@ -130,6 +130,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -130,6 +130,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector_key_tags *key_tags; struct flow_dissector_key_tags *key_tags;
struct flow_dissector_key_keyid *key_keyid; struct flow_dissector_key_keyid *key_keyid;
u8 ip_proto = 0; u8 ip_proto = 0;
bool ret = false;
if (!data) { if (!data) {
data = skb->data; data = skb->data;
...@@ -171,7 +172,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -171,7 +172,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
ip: ip:
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph); iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
if (!iph || iph->ihl < 5) if (!iph || iph->ihl < 5)
return false; goto out_bad;
nhoff += iph->ihl * 4; nhoff += iph->ihl * 4;
ip_proto = iph->protocol; ip_proto = iph->protocol;
...@@ -197,7 +198,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -197,7 +198,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
ipv6: ipv6:
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph); iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
if (!iph) if (!iph)
return false; goto out_bad;
ip_proto = iph->nexthdr; ip_proto = iph->nexthdr;
nhoff += sizeof(struct ipv6hdr); nhoff += sizeof(struct ipv6hdr);
...@@ -234,7 +235,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -234,7 +235,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan); vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan);
if (!vlan) if (!vlan)
return false; goto out_bad;
if (skb_flow_dissector_uses_key(flow_dissector, if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_VLANID)) { FLOW_DISSECTOR_KEY_VLANID)) {
...@@ -256,7 +257,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -256,7 +257,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
} *hdr, _hdr; } *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr) if (!hdr)
return false; goto out_bad;
proto = hdr->proto; proto = hdr->proto;
nhoff += PPPOE_SES_HLEN; nhoff += PPPOE_SES_HLEN;
switch (proto) { switch (proto) {
...@@ -265,7 +266,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -265,7 +266,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
case htons(PPP_IPV6): case htons(PPP_IPV6):
goto ipv6; goto ipv6;
default: default:
return false; goto out_bad;
} }
} }
case htons(ETH_P_TIPC): { case htons(ETH_P_TIPC): {
...@@ -275,9 +276,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -275,9 +276,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
} *hdr, _hdr; } *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr) if (!hdr)
return false; goto out_bad;
key_basic->n_proto = proto;
key_control->thoff = (u16)nhoff;
if (skb_flow_dissector_uses_key(flow_dissector, if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_TIPC_ADDRS)) { FLOW_DISSECTOR_KEY_TIPC_ADDRS)) {
...@@ -287,7 +286,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -287,7 +286,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
key_addrs->tipcaddrs.srcnode = hdr->srcnode; key_addrs->tipcaddrs.srcnode = hdr->srcnode;
key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC_ADDRS; key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC_ADDRS;
} }
return true; goto out_good;
} }
case htons(ETH_P_MPLS_UC): case htons(ETH_P_MPLS_UC):
...@@ -297,7 +296,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -297,7 +296,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
hlen, &_hdr); hlen, &_hdr);
if (!hdr) if (!hdr)
return false; goto out_bad;
if ((ntohl(hdr[0].entry) & MPLS_LS_LABEL_MASK) >> if ((ntohl(hdr[0].entry) & MPLS_LS_LABEL_MASK) >>
MPLS_LS_LABEL_SHIFT == MPLS_LABEL_ENTROPY) { MPLS_LS_LABEL_SHIFT == MPLS_LABEL_ENTROPY) {
...@@ -310,21 +309,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -310,21 +309,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
htonl(MPLS_LS_LABEL_MASK); htonl(MPLS_LS_LABEL_MASK);
} }
key_basic->n_proto = proto; goto out_good;
key_basic->ip_proto = ip_proto;
key_control->thoff = (u16)nhoff;
return true;
} }
return true; goto out_good;
} }
case htons(ETH_P_FCOE): case htons(ETH_P_FCOE):
key_control->thoff = (u16)(nhoff + FCOE_HEADER_LEN); key_control->thoff = (u16)(nhoff + FCOE_HEADER_LEN);
/* fall through */ /* fall through */
default: default:
return false; goto out_bad;
} }
ip_proto_again: ip_proto_again:
...@@ -337,7 +332,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -337,7 +332,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr) if (!hdr)
return false; goto out_bad;
/* /*
* Only look inside GRE if version zero and no * Only look inside GRE if version zero and no
* routing * routing
...@@ -357,7 +352,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -357,7 +352,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
data, hlen, &_keyid); data, hlen, &_keyid);
if (!keyid) if (!keyid)
return false; goto out_bad;
if (skb_flow_dissector_uses_key(flow_dissector, if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_GRE_KEYID)) { FLOW_DISSECTOR_KEY_GRE_KEYID)) {
...@@ -378,7 +373,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -378,7 +373,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
sizeof(_eth), sizeof(_eth),
data, hlen, &_eth); data, hlen, &_eth);
if (!eth) if (!eth)
return false; goto out_bad;
proto = eth->h_proto; proto = eth->h_proto;
nhoff += sizeof(*eth); nhoff += sizeof(*eth);
} }
...@@ -395,7 +390,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -395,7 +390,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr), opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr),
data, hlen, &_opthdr); data, hlen, &_opthdr);
if (!opthdr) if (!opthdr)
return false; goto out_bad;
ip_proto = opthdr[0]; ip_proto = opthdr[0];
nhoff += (opthdr[1] + 1) << 3; nhoff += (opthdr[1] + 1) << 3;
...@@ -415,10 +410,6 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -415,10 +410,6 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
break; break;
} }
key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto;
key_control->thoff = (u16)nhoff;
if (skb_flow_dissector_uses_key(flow_dissector, if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_PORTS)) { FLOW_DISSECTOR_KEY_PORTS)) {
key_ports = skb_flow_dissector_target(flow_dissector, key_ports = skb_flow_dissector_target(flow_dissector,
...@@ -428,7 +419,15 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -428,7 +419,15 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
data, hlen); data, hlen);
} }
return true; out_good:
ret = true;
out_bad:
key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto;
key_control->thoff = (u16)nhoff;
return ret;
} }
EXPORT_SYMBOL(__skb_flow_dissect); EXPORT_SYMBOL(__skb_flow_dissect);
......
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