Skip to content

Commit

Permalink
issue: 1284069 Redirect traffic from tap to netvsc
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ivanov <[email protected]>
  • Loading branch information
igor-ivanov authored and liranoz12 committed May 24, 2018
1 parent aa127b3 commit 8b3c62c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tools/daemon/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ int add_flow(pid_t pid, struct store_flow *value)
/* Cleanup from possible failure during last daemon session */
sys_exec("tc qdisc del dev %s handle ffff: ingress > /dev/null 2>&1 || echo $?", if_name);

/* Create filter to redirect traffic from netvsc device to tap device */
out_buf = sys_exec("tc qdisc add dev %s handle ffff: ingress > /dev/null 2>&1 || echo $?", if_name);
if (NULL == out_buf || (out_buf[0] != '\0' && out_buf[0] != '0')) {
log_error("[%d] failed tc qdisc add dev %s output: %s\n",
Expand All @@ -191,6 +192,28 @@ int add_flow(pid_t pid, struct store_flow *value)
goto err;
}

/* This cleanup is done just to support verification */
sys_exec("tc qdisc del dev %s handle ffff: ingress > /dev/null 2>&1 || echo $?", tap_name);

/* Create filter to redirect traffic from tap device to netvsc device */
out_buf = sys_exec("tc qdisc add dev %s handle ffff: ingress > /dev/null 2>&1 || echo $?", tap_name);
if (NULL == out_buf || (out_buf[0] != '\0' && out_buf[0] != '0')) {
log_error("[%d] failed tc qdisc add dev %s output: %s\n",
pid, tap_name, (out_buf ? out_buf : "n/a"));
free(cur_element);
rc = -EFAULT;
goto err;
}
out_buf = sys_exec("tc filter add dev %s parent ffff: protocol all u32 match u8 0 0 action mirred egress redirect dev %s > /dev/null 2>&1 || echo $?",
tap_name, if_name);
if (NULL == out_buf || (out_buf[0] != '\0' && out_buf[0] != '0')) {
log_error("[%d] failed tc filter add dev %s output: %s\n",
pid, tap_name, (out_buf ? out_buf : "n/a"));
free(cur_element);
rc = -EFAULT;
goto err;
}

INIT_LIST_HEAD(&cur_element->list);
cur_element->ref = 0;
cur_element->value[0] = value->if_id;
Expand Down

0 comments on commit 8b3c62c

Please sign in to comment.