Skip to content

Commit

Permalink
dp-core: vr_pexpand_head might return new vr_packet
Browse files Browse the repository at this point in the history
Changes required to support Contrail on Windows.
- Implementation of vr_pexpand_head on Windows might clone the packet,
  if not enough head space is available. This cloned packet will receive
  the new vr_packet struct, to which pointer will then be returned.
  This change prepares dp-core codebase for this change in semantics.

Initial work:
  https://github.com/codilime/contrail-vrouter/commits/windows

Change-Id: Ie2e7dc3bb00ed7e84189126cd0ab1468ad2d787a
Partial-Bug: #1734699
  • Loading branch information
Dariusz Sosnowski authored and jablonskim committed Jan 4, 2018
1 parent 7e1320e commit 9a02fa0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 65 deletions.
16 changes: 8 additions & 8 deletions dp-core/vr_datapath.c
Expand Up @@ -738,36 +738,36 @@ vr_untag_pkt(struct vr_packet *pkt)
* modify the data pointer of skb
*/
int
vr_tag_pkt(struct vr_packet *pkt, unsigned short vlan_id, bool force_tag)
vr_tag_pkt(struct vr_packet **pkt, unsigned short vlan_id, bool force_tag)
{
uint8_t priority = 0;
struct vr_packet *tmp_pkt;
struct vr_eth *new_eth, *eth;
unsigned short *vlan_tag;

eth = (struct vr_eth *)pkt_data(pkt);
eth = (struct vr_eth *)pkt_data(*pkt);
if (!force_tag) {
if (eth->eth_proto == htons(VR_ETH_PROTO_VLAN))
return 0;
}

if (pkt_head_space(pkt) < VR_VLAN_HLEN) {
tmp_pkt = vr_pexpand_head(pkt, VR_VLAN_HLEN - pkt_head_space(pkt));
if (pkt_head_space(*pkt) < VR_VLAN_HLEN) {
tmp_pkt = vr_pexpand_head(*pkt, VR_VLAN_HLEN - pkt_head_space(*pkt));
if (!tmp_pkt) {
return -1;
}
pkt = tmp_pkt;
*pkt = tmp_pkt;
}

new_eth = (struct vr_eth *)pkt_push(pkt, VR_VLAN_HLEN);
new_eth = (struct vr_eth *)pkt_push(*pkt, VR_VLAN_HLEN);
if (!new_eth)
return -1;

memmove(new_eth, eth, (2 * VR_ETHER_ALEN));
new_eth->eth_proto = htons(VR_ETH_PROTO_VLAN);
vlan_tag = (unsigned short *)(new_eth + 1);
if (pkt->vp_priority != VP_PRIORITY_INVALID)
priority = pkt->vp_priority;
if ((*pkt)->vp_priority != VP_PRIORITY_INVALID)
priority = (*pkt)->vp_priority;

*vlan_tag = htons((priority << VR_VLAN_PRIORITY_SHIFT) | vlan_id);

Expand Down
42 changes: 23 additions & 19 deletions dp-core/vr_interface.c
Expand Up @@ -97,22 +97,24 @@ vif_drop_pkt(struct vr_interface *vif, struct vr_packet *pkt, bool input)
* passing us valid rewrite ptr and len and will not check for those
*/
static int
vif_cmn_rewrite(struct vr_interface *vif, struct vr_packet *pkt,
vif_cmn_rewrite(struct vr_interface *vif, struct vr_packet **pkt,
struct vr_forwarding_md *fmd, unsigned char *rewrite,
unsigned short len)
{
unsigned char *head;
struct vr_packet *expanded_pkt;

if (!len)
return 0;

if (pkt_head_space(pkt) < len) {
pkt = vr_pexpand_head(pkt, len - pkt_head_space(pkt));
if (!pkt)
if (pkt_head_space(*pkt) < len) {
expanded_pkt = vr_pexpand_head(*pkt, len - pkt_head_space(*pkt));
if (!expanded_pkt)
return -ENOMEM;
*pkt = expanded_pkt;
}

head = pkt_push(pkt, len);
head = pkt_push(*pkt, len);
if (!head)
return -ENOMEM;

Expand Down Expand Up @@ -278,32 +280,34 @@ vif_mirror(struct vr_interface *vif, struct vr_packet *pkt,

/* agent driver */
static int
agent_set_rewrite(struct vr_interface *vif, struct vr_packet *pkt,
agent_set_rewrite(struct vr_interface *vif, struct vr_packet **pkt,
struct vr_forwarding_md *fmd, unsigned char *rewrite,
unsigned short len)
{
unsigned char *head;
unsigned int hdr_len;
struct agent_hdr *hdr;
struct vr_packet *expanded_pkt;

vr_preset(pkt);
vr_preset(*pkt);

hdr_len = sizeof(struct agent_hdr) + len;
if (pkt_head_space(pkt) < hdr_len) {
pkt = vr_pexpand_head(pkt, hdr_len - pkt_head_space(pkt));
if (!pkt)
if (pkt_head_space(*pkt) < hdr_len) {
expanded_pkt = vr_pexpand_head(*pkt, hdr_len - pkt_head_space(*pkt));
if (!expanded_pkt)
return -ENOMEM;
*pkt = expanded_pkt;
}

head = pkt_push(pkt, hdr_len);
head = pkt_push(*pkt, hdr_len);
if (!head)
return -ENOMEM;

/* copy the rewrite first */
memcpy(head, rewrite, len);

hdr = (struct agent_hdr *)(head + len);
hdr->hdr_ifindex = htons(pkt->vp_if->vif_idx);
hdr->hdr_ifindex = htons((*pkt)->vp_if->vif_idx);
hdr->hdr_vrf = htons(fmd->fmd_dvrf);
/* this needs some thought */
hdr->hdr_cmd = htons(AGENT_TRAP_NEXTHOP);
Expand Down Expand Up @@ -866,7 +870,7 @@ vlan_tx(struct vr_interface *vif, struct vr_packet *pkt,
if (fmd->fmd_vlan != VLAN_ID_INVALID)
force_tag = true;

if (vr_tag_pkt(pkt, vif->vif_ovlan_id, force_tag)) {
if (vr_tag_pkt(&pkt, vif->vif_ovlan_id, force_tag)) {
goto drop;
}
vr_pset_data(pkt, pkt->vp_data);
Expand Down Expand Up @@ -1199,7 +1203,7 @@ tun_rx(struct vr_interface *vif, struct vr_packet *pkt,
}

static int
eth_set_rewrite(struct vr_interface *vif, struct vr_packet *pkt,
eth_set_rewrite(struct vr_interface *vif, struct vr_packet **pkt,
struct vr_forwarding_md *fmd, unsigned char *rewrite,
unsigned short len)
{
Expand All @@ -1211,10 +1215,10 @@ eth_set_rewrite(struct vr_interface *vif, struct vr_packet *pkt,
* tunneled packet and not from Agent. Otherwise, apply the new
* rewrite data
*/
if ((pkt->vp_if->vif_type == VIF_TYPE_HOST) &&
(!(pkt->vp_flags & VP_FLAG_FROM_DP)) &&
((pkt->vp_type == VP_TYPE_IP) || (pkt->vp_type == VP_TYPE_IP6))) {
vr_preset(pkt);
if (((*pkt)->vp_if->vif_type == VIF_TYPE_HOST) &&
(!((*pkt)->vp_flags & VP_FLAG_FROM_DP)) &&
(((*pkt)->vp_type == VP_TYPE_IP) || ((*pkt)->vp_type == VP_TYPE_IP6))) {
vr_preset(*pkt);
return 0;
}

Expand Down Expand Up @@ -1345,7 +1349,7 @@ eth_tx(struct vr_interface *vif, struct vr_packet *pkt,
} else if (vif_is_fabric(vif)) {
vlan_id = vr_fmd_get_mirror_vlan(fmd);
if (vlan_id != FMD_MIRROR_INVALID_DATA) {
vr_tag_pkt(pkt, vlan_id, force_tag);
vr_tag_pkt(&pkt, vlan_id, force_tag);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_mirror.c
Expand Up @@ -453,7 +453,7 @@ vr_mirror(struct vrouter *router, uint8_t mirror_id, struct vr_packet *pkt,

clone_len = 0;

if (pkt_nh->nh_dev->vif_set_rewrite(pkt_nh->nh_dev, pkt, fmd,
if (pkt_nh->nh_dev->vif_set_rewrite(pkt_nh->nh_dev, &pkt, fmd,
pkt_nh->nh_data, pkt_nh->nh_encap_len) < 0) {
drop_reason = VP_DROP_REWRITE_FAIL;
goto fail;
Expand Down

0 comments on commit 9a02fa0

Please sign in to comment.