Skip to content

Commit

Permalink
flow_dissector: Jump to exit code in __skb_flow_dissect
Browse files Browse the repository at this point in the history
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: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
tomratbert authored and davem330 committed Sep 1, 2015
1 parent c6cc1ca commit a6e544b
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions net/core/flow_dissector.c
Expand Up @@ -130,6 +130,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector_key_tags *key_tags;
struct flow_dissector_key_keyid *key_keyid;
u8 ip_proto = 0;
bool ret = false;

if (!data) {
data = skb->data;
Expand Down Expand Up @@ -171,7 +172,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
ip:
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
if (!iph || iph->ihl < 5)
return false;
goto out_bad;
nhoff += iph->ihl * 4;

ip_proto = iph->protocol;
Expand All @@ -197,7 +198,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
ipv6:
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
if (!iph)
return false;
goto out_bad;

ip_proto = iph->nexthdr;
nhoff += sizeof(struct ipv6hdr);
Expand Down Expand Up @@ -234,7 +235,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,

vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan);
if (!vlan)
return false;
goto out_bad;

if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_VLANID)) {
Expand All @@ -256,7 +257,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
} *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr)
return false;
goto out_bad;
proto = hdr->proto;
nhoff += PPPOE_SES_HLEN;
switch (proto) {
Expand All @@ -265,7 +266,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
case htons(PPP_IPV6):
goto ipv6;
default:
return false;
goto out_bad;
}
}
case htons(ETH_P_TIPC): {
Expand All @@ -275,9 +276,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
} *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr)
return false;
key_basic->n_proto = proto;
key_control->thoff = (u16)nhoff;
goto out_bad;

if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_TIPC_ADDRS)) {
Expand All @@ -287,7 +286,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
key_addrs->tipcaddrs.srcnode = hdr->srcnode;
key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC_ADDRS;
}
return true;
goto out_good;
}

case htons(ETH_P_MPLS_UC):
Expand All @@ -297,7 +296,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
hlen, &_hdr);
if (!hdr)
return false;
goto out_bad;

if ((ntohl(hdr[0].entry) & MPLS_LS_LABEL_MASK) >>
MPLS_LS_LABEL_SHIFT == MPLS_LABEL_ENTROPY) {
Expand All @@ -310,21 +309,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
htonl(MPLS_LS_LABEL_MASK);
}

key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto;
key_control->thoff = (u16)nhoff;

return true;
goto out_good;
}

return true;
goto out_good;
}

case htons(ETH_P_FCOE):
key_control->thoff = (u16)(nhoff + FCOE_HEADER_LEN);
/* fall through */
default:
return false;
goto out_bad;
}

ip_proto_again:
Expand All @@ -337,7 +332,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,

hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr)
return false;
goto out_bad;
/*
* Only look inside GRE if version zero and no
* routing
Expand All @@ -357,7 +352,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
data, hlen, &_keyid);

if (!keyid)
return false;
goto out_bad;

if (skb_flow_dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_GRE_KEYID)) {
Expand All @@ -378,7 +373,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
sizeof(_eth),
data, hlen, &_eth);
if (!eth)
return false;
goto out_bad;
proto = eth->h_proto;
nhoff += sizeof(*eth);
}
Expand All @@ -395,7 +390,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr),
data, hlen, &_opthdr);
if (!opthdr)
return false;
goto out_bad;

ip_proto = opthdr[0];
nhoff += (opthdr[1] + 1) << 3;
Expand All @@ -415,10 +410,6 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
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,
FLOW_DISSECTOR_KEY_PORTS)) {
key_ports = skb_flow_dissector_target(flow_dissector,
Expand All @@ -428,7 +419,15 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
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);

Expand Down

0 comments on commit a6e544b

Please sign in to comment.