Skip to content

Commit

Permalink
Drop ICMP error packets for ICMP errors
Browse files Browse the repository at this point in the history
In case of ICMP error packets for ICMP errors, we were not initializing
flow key and trying to form a flow out of that key, resulting in wrong
key length and corrupted flow entry(s).

We will drop such packets.

Change-Id: Idae46a7e128482ad89da8b5bd1bd0ef6b17ef28e
Closes-BUG: #1556363
  • Loading branch information
anandhk-juniper committed Mar 31, 2016
1 parent 27904db commit 4e91f85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dp-core/vr_proto_ip.c
Expand Up @@ -838,6 +838,8 @@ vr_inet_proto_flow(struct vrouter *router, unsigned short vrf,
struct vr_packet *pkt, uint16_t vlan, struct vr_ip *ip,
struct vr_flow *flow_p)
{
int ret = 0;

unsigned short *t_hdr, sport, dport;
unsigned short nh_id;

Expand All @@ -849,13 +851,21 @@ vr_inet_proto_flow(struct vrouter *router, unsigned short vrf,
if (ip->ip_proto == VR_IP_PROTO_ICMP) {
icmph = (struct vr_icmp *)t_hdr;
if (vr_icmp_error(icmph)) {
/* we will generate a flow only for the first icmp error */
if ((unsigned char *)ip == pkt_network_header(pkt)) {
vr_inet_proto_flow(router, vrf, pkt, vlan,
ret = vr_inet_proto_flow(router, vrf, pkt, vlan,
(struct vr_ip *)(icmph + 1), flow_p);
if (ret)
return ret;

vr_inet_flow_swap(flow_p);
} else {
/* for icmp error for icmp error, we will drop the packet */
return -1;
}

return 0;
sport = flow_p->flow4_sport;
dport = flow_p->flow4_dport;
} else if (vr_icmp_echo(icmph)) {
sport = icmph->icmp_eid;
dport = VR_ICMP_TYPE_ECHO_REPLY;
Expand Down Expand Up @@ -983,7 +993,7 @@ vr_inet_flow_lookup(struct vrouter *router, struct vr_packet *pkt,
vr_enqueue_to_assembler(router, pkt, fmd);
} else {
/* unlikely to be hit. you can safely discount misc drops here */
vr_pfree(pkt, VP_DROP_FRAGMENTS);
vr_pfree(pkt, VP_DROP_MISC);
}
return FLOW_CONSUMED;
}
Expand Down
18 changes: 14 additions & 4 deletions dp-core/vr_proto_ip6.c
Expand Up @@ -173,6 +173,7 @@ vr_inet6_form_flow(struct vrouter *router, unsigned short vrf,
struct vr_packet *pkt, uint16_t vlan, struct vr_ip6 *ip6,
struct vr_flow *flow_p)
{
int ret = 0;
unsigned short *t_hdr, sport, dport;
unsigned short nh_id;

Expand All @@ -183,10 +184,19 @@ vr_inet6_form_flow(struct vrouter *router, unsigned short vrf,
if (ip6->ip6_nxt == VR_IP_PROTO_ICMP6) {
icmph = (struct vr_icmp *)t_hdr;
if (vr_icmp6_error(icmph)) {
vr_inet6_form_flow(router, vrf, pkt, vlan,
(struct vr_ip6 *)(icmph + 1), flow_p);
vr_inet6_flow_swap(flow_p);
return 0;
if ((unsigned char *)ip6 == pkt_network_header(pkt)) {
ret = vr_inet6_form_flow(router, vrf, pkt, vlan,
(struct vr_ip6 *)(icmph + 1), flow_p);
if (ret)
return ret;

vr_inet6_flow_swap(flow_p);
} else {
return -1;
}

sport = flow_p->flow6_sport;
dport = flow_p->flow6_dport;
} else if ((icmph->icmp_type == VR_ICMP6_TYPE_ECHO_REQ) ||
(icmph->icmp_type == VR_ICMP6_TYPE_ECHO_REPLY)) {
sport = icmph->icmp_eid;
Expand Down

0 comments on commit 4e91f85

Please sign in to comment.