Skip to content

Commit

Permalink
Merge pull request #81 from jaysheth2/jay-TMT-tunnel1
Browse files Browse the repository at this point in the history
Fix to allow all tunnel types for encapsulating mirrored traffic
  • Loading branch information
sanfern authored Jul 9, 2024
2 parents d84f4a5 + 17a7f31 commit 3d2af73
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
4 changes: 2 additions & 2 deletions traffic-mirroring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Usage
\--direction=ingress \\
\--map-name=\<location of the tc-root map for chaining\> \\
\--src-address=\<list of the source addresses (Use 0.0.0.0 for mirroring packets with "any" src IP)\> \\
\--tunnel-type=gue \\
\--tunnel-interface-name=gue1 \\
\--tunnel-local-port=\<local tunnel port\> \\
\--tunnel-remote-port=\<remote tunnel port\> \\
\--tunnel-remote-address=\<local tunnel IP address\> \\
Expand All @@ -93,7 +93,7 @@ Usage
\--direction=egress \\
\--map-name=\<location of the tc-root map for chaining\> \\
\--dst-address=\<list of the destination addresses (Use 0.0.0.0 for mirroring packets with "any" dst IP)\> \\
\--tunnel-type=gue \\
\--tunnel-interface-name=gue1 \\
\--tunnel-local-port=\<local tunnel port\> \\
\--tunnel-remote-port=\<remote tunnel port\> \\
\--tunnel-remote-address=\<local tunnel IP address\> \\
Expand Down
51 changes: 21 additions & 30 deletions traffic-mirroring/mirroring.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,7 @@ bool validate_netlink(struct route_config *r)
fprintf(stderr, "ERR: No routing information provided\n");
return false;
}
if (strcmp(r->encap_type, "gue") == 0)
{
r->type = "ipip";
r->name = "gue1";
}
else
{
fprintf(stderr, "ERR: --tunnel-type unknown value\n");
return false;
}
r->name = "tunnelRoute";

getifaddrs(&ifap);
for (ifa = ifap; ifa; ifa = ifa->ifa_next)
Expand Down Expand Up @@ -311,19 +302,20 @@ static const struct option long_options[] = {
{"iface", required_argument, NULL, 'i'},
{"redirect-to", required_argument, NULL, 'e'},
/* HINT assign: optional_arguments with '=' */
{"direction", optional_argument, NULL, 't'},
{"src-address", optional_argument, NULL, 's'},
{"dst-address", optional_argument, NULL, 'd'},
{"gtw-address", optional_argument, NULL, 'g'},
{"src-port", optional_argument, NULL, 'u'},
{"dst-port", optional_argument, NULL, 'U'},
{"protocol", optional_argument, NULL, 'r'},
{"tunnel-remote-address", optional_argument, NULL, 'D'},
{"tunnel-type", optional_argument, NULL, 'T'},
{"tunnel-local-port", optional_argument, NULL, 'p'},
{"tunnel-remote-port", optional_argument, NULL, 'P'},
{"quiet", no_argument, NULL, 'q'},
{0, 0, NULL, 0}};
{ "direction", optional_argument, NULL, 't' },
{ "src-address", optional_argument, NULL, 's' },
{ "dst-address", optional_argument, NULL, 'd' },
{ "gtw-address", optional_argument, NULL, 'g' },
{ "src-port", optional_argument, NULL, 'u' },
{ "dst-port", optional_argument, NULL, 'U' },
{ "protocol", optional_argument, NULL, 'r' },
{ "tunnel-remote-address", optional_argument, NULL, 'D' },
{ "tunnel-interface-name", optional_argument, NULL, 'T' },
{ "tunnel-local-port", optional_argument, NULL, 'p' },
{ "tunnel-remote-port", optional_argument, NULL, 'P' },
{ "quiet", no_argument, NULL, 'q' },
{ 0, 0, NULL, 0 }
};

static void usage(char *argv[])
{
Expand Down Expand Up @@ -837,12 +829,11 @@ int main(int argc, char **argv)
r.dport[l] = '\0';
}
break;
case 'T':
if (optarg)
{
r.encap_type = optarg;
l = get_length(r.encap_type);
r.encap_type[l] = '\0';
case 'T':
if (optarg) {
r.encap_interface_name = optarg;
l = get_length(r.encap_interface_name);
r.encap_interface_name[l] = '\0';
}
break;
case 'q':
Expand Down Expand Up @@ -1053,7 +1044,7 @@ int main(int argc, char **argv)
// reset errno
errno = 0;

tunnel_ifindex = if_nametoindex(r.name);
tunnel_ifindex = if_nametoindex(r.encap_interface_name);
/* Only update/set egress port when set via cmdline */
int redirect_iface_key = 0;
if (tunnel_ifindex != -1)
Expand Down
2 changes: 1 addition & 1 deletion traffic-mirroring/mirroring.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct route_config {
char *nic_name;
int nic_id;
char *type;
char *encap_type;
char *encap_interface_name;
};

static const char *redirect_mapfile = "redirect_iface";
Expand Down

0 comments on commit 3d2af73

Please sign in to comment.