Skip to content

Commit

Permalink
Provision to take mirror source ip from the packet
Browse files Browse the repository at this point in the history
vRouter has to make provision to allow source ip of the mirror tunnel
to come from the original packet. Till now, we were using the vhost ip
address, which may not make sense in the vrf to which the mirror vm
belongs.

Change-Id: I3147d57aa16ad808327036db557387fb2ef3782c
Closes-BUG: #1545590
  • Loading branch information
anandhk-juniper committed Mar 16, 2016
1 parent ff6eacc commit c4cb872
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
42 changes: 39 additions & 3 deletions dp-core/vr_nexthop.c
Expand Up @@ -1229,10 +1229,25 @@ nh_discard(struct vr_packet *pkt, struct vr_nexthop *nh,
return 0;
}

static int
nh_generate_sip(struct vr_nexthop *nh, struct vr_packet *pkt)
{
struct vr_ip *iph;

iph = (struct vr_ip *)pkt_network_header(pkt);
if (pkt->vp_type == VP_TYPE_IP) {
return iph->ip_saddr;
}

return 0;
}

static int
nh_udp_tunnel(struct vr_packet *pkt, struct vr_nexthop *nh,
struct vr_forwarding_md *fmd)
{
uint32_t sip = 0;

struct vr_packet *tmp;
struct vr_ip *ip;
struct vr_udp *udp;
Expand All @@ -1251,11 +1266,32 @@ nh_udp_tunnel(struct vr_packet *pkt, struct vr_nexthop *nh,
goto send_fail;
}

if (nh_udp_tunnel_helper(pkt, nh->nh_udp_tun_sport,
nh->nh_udp_tun_dport, nh->nh_udp_tun_sip,
nh->nh_udp_tun_dip) == false) {
if (nh->nh_family == AF_INET) {
if (nh->nh_flags & NH_FLAG_TUNNEL_SIP_COPY) {
sip = nh_generate_sip(nh, pkt);
}

if (!sip) {
sip = nh->nh_udp_tun_sip;
}

if (nh_udp_tunnel_helper(pkt, nh->nh_udp_tun_sport,
nh->nh_udp_tun_dport, sip,
nh->nh_udp_tun_dip) == false) {
goto send_fail;
}

if (pkt_len(pkt) > ((1 << sizeof(ip->ip_len) * 8)))
goto send_fail;

ip = (struct vr_ip *)(pkt_data(pkt));
udp = (struct vr_udp *)((char *)ip + ip->ip_hl * 4);
udp->udp_csum = vr_ip_partial_csum(ip);

} else {
goto send_fail;
}

pkt_set_network_header(pkt, pkt->vp_data);

if (pkt_len(pkt) > ((1 << sizeof(ip->ip_len) * 8)))
Expand Down
1 change: 1 addition & 0 deletions include/vr_nexthop.h
Expand Up @@ -55,6 +55,7 @@ enum nexthop_type {
#define NH_FLAG_VNID 0x08000
#define NH_FLAG_ROUTE_LOOKUP 0x10000
#define NH_FLAG_UNKNOWN_UC_FLOOD 0x20000
#define NH_FLAG_TUNNEL_SIP_COPY 0x40000

#define NH_SOURCE_INVALID 0
#define NH_SOURCE_VALID 1
Expand Down
4 changes: 4 additions & 0 deletions utils/nh.c
Expand Up @@ -166,6 +166,10 @@ nh_flags(uint32_t flags, uint8_t type, char *ptr)
case NH_FLAG_UNKNOWN_UC_FLOOD:
strcat(ptr, "Unicast Flood, ");
break;

case NH_FLAG_TUNNEL_SIP_COPY:
strcat(ptr, "Copy SIP, ");
break;
}
}
return ptr;
Expand Down

0 comments on commit c4cb872

Please sign in to comment.