Skip to content

Commit

Permalink
Manipulating the TTL of the Packet
Browse files Browse the repository at this point in the history
Right now the TTL of the packet is not overwritten by Vrouter. It is
only decremented like a hop, for the required packets. But BGP packets
in VM (due to BGP as service), can come to Vrouter to with ttl of 1. In
a multi hop environment, we require this ttl to be more than 1. For this
purpose flow entry is added with another ttl field and if Agent sets
this, vrouter unconditionally sets this ttl in the packet and calculates
the checksum again.

partial-bug: #1567586

Change-Id: I53a192666731f4c3662e3791006dd7294bccf116
  • Loading branch information
divakardhar committed Aug 1, 2016
1 parent b697f11 commit 14f0f11
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
21 changes: 21 additions & 0 deletions dp-core/vr_flow.c
Expand Up @@ -221,6 +221,7 @@ __vr_flow_reset_entry(struct vrouter *router, struct vr_flow_entry *fe)
fe->fe_flags &=
(VR_FLOW_FLAG_ACTIVE | VR_FLOW_FLAG_EVICTED |
VR_FLOW_FLAG_NEW_FLOW | VR_FLOW_FLAG_DELETE_MARKED);
fe->fe_ttl = 0;

return;
}
Expand Down Expand Up @@ -777,6 +778,8 @@ vr_flow_action(struct vrouter *router, struct vr_flow_entry *fe,
struct vr_forwarding_md *fmd)
{
int valid_src;
unsigned int ip_inc_diff_cksum = 0;
struct vr_ip *ip;

flow_result_t result;

Expand Down Expand Up @@ -858,6 +861,22 @@ vr_flow_action(struct vrouter *router, struct vr_flow_entry *fe,
break;
}

if (result == FLOW_FORWARD) {
if (pkt->vp_type == VP_TYPE_IP) {
ip = (struct vr_ip *)pkt_network_header(pkt);
if (ip) {
if (fe->fe_ttl && (fe->fe_ttl != ip->ip_ttl)) {
vr_incremental_diff(ip->ip_ttl, fe->fe_ttl, &ip_inc_diff_cksum);
ip->ip_ttl = fe->fe_ttl;

if (ip_inc_diff_cksum)
vr_ip_incremental_csum(ip, ip_inc_diff_cksum);
}
}
}
}


if (fe->fe_tcp_flags & VR_FLOW_TCP_DEAD)
vr_flow_mark_evict(router, fe, index);

Expand Down Expand Up @@ -1949,6 +1968,8 @@ vr_flow_set(struct vrouter *router, vr_flow_req *req)
fe->fe_action = req->fr_action;
}

fe->fe_ttl = req->fr_ttl;

if (fe->fe_action == VR_FLOW_ACTION_DROP)
fe->fe_drop_reason = (uint8_t)req->fr_drop_reason;

Expand Down
3 changes: 2 additions & 1 deletion dp-core/vr_proto_ip.c
Expand Up @@ -97,7 +97,8 @@ vr_ip_update_csum(struct vr_packet *pkt, unsigned int ip_inc, unsigned int inc)
unsigned short *csump;

ip = (struct vr_ip *)pkt_network_header(pkt);
ip->ip_csum = vr_ip_csum(ip);
if (ip_inc)
vr_ip_incremental_csum(ip, ip_inc);

if (ip->ip_proto == VR_IP_PROTO_TCP) {
tcp = (struct vr_tcp *)((unsigned char *)ip + ip->ip_hl * 4);
Expand Down
4 changes: 2 additions & 2 deletions include/vr_flow.h
Expand Up @@ -301,7 +301,7 @@ struct vr_flow_queue {

struct vr_dummy_flow_entry {
vr_hentry_t fe_hentry;
uint8_t fe_pack_hentry;
uint8_t fe_ttl;
int16_t fe_qos_id;
struct vr_flow fe_key;
uint8_t fe_gen_id;
Expand All @@ -328,7 +328,7 @@ struct vr_dummy_flow_entry {
/* do not change. any field positions as it might lead to incompatibility */
struct vr_flow_entry {
vr_hentry_t fe_hentry;
uint8_t fe_pack_hentry;
uint8_t fe_ttl;
int16_t fe_qos_id;
struct vr_flow fe_key;
uint8_t fe_gen_id;
Expand Down
8 changes: 7 additions & 1 deletion include/vr_packet.h
Expand Up @@ -412,7 +412,12 @@ vr_ip_incremental_csum(struct vr_ip *ip, unsigned int diff)
{
unsigned int csum;

diff &= 0xffff;
diff = (diff >> 16) + (diff & 0xffff);
if (diff >> 16) {
diff &= 0xffff;
diff += 1;
}

csum = ~(ip->ip_csum) & 0xffff;
csum += diff;
csum = (csum >> 16) + (csum & 0xffff);
Expand Down Expand Up @@ -707,6 +712,7 @@ vr_ip_transport_header_valid(struct vr_ip *iph)
}



#define VR_TCP_FLAG_FIN 0x0001
#define VR_TCP_FLAG_SYN 0x0002
#define VR_TCP_FLAG_RST 0x0004
Expand Down
1 change: 1 addition & 0 deletions sandesh/vr.sandesh
Expand Up @@ -191,6 +191,7 @@ buffer sandesh vr_flow_req {
36: i32 fr_oflow_entries;
37: byte fr_gen_id;
38: i16 fr_qos_id;
39: byte fr_ttl;
}

buffer sandesh vr_vrf_assign_req {
Expand Down
1 change: 1 addition & 0 deletions utils/flow.c
Expand Up @@ -1405,6 +1405,7 @@ flow_dump_table(struct flow_table *ft)
printf(", %d, ", fe->fe_sec_mirror_id);
}
printf(" SPort %d", fe->fe_udp_src_port);
printf(" TTL %d", fe->fe_ttl);
printf(")");
}

Expand Down

0 comments on commit 14f0f11

Please sign in to comment.