Skip to content

Commit a429c40

Browse files
authored
Merge pull request #110 from sanfern/sanfern-upgrade-issue
Update the version argument for the bpf programs Santhosh Fernandes <santhosh.fernandes@gmail.com>
2 parents 37a54c5 + db206ec commit a429c40

File tree

8 files changed

+56
-39
lines changed

8 files changed

+56
-39
lines changed

connection-limit/connection_limit_user.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ static int is_ipv6_loopback(struct in6_addr *addr6);
4141
static int str_split(char *input, char *delimiter, char *word_array[]);
4242
static long strtoi(char *str, int base);
4343
static void addr6_parser(char *input, struct in6_addr *localaddr);
44-
int get_bpf_map_file(const char *ifname, const char *map_name, char *map_file);
44+
int get_bpf_map_file(const char *ifname, const char *version, const char *map_name, char *map_file);
4545
void close_fd(int fd);
4646
void close_all_fds(void);
4747

4848
static const struct option long_options[] = {
4949
{"help", no_argument, NULL, 'h'},
5050
{"iface", required_argument, NULL, 'i'},
51-
{"verbose", optional_argument, NULL, 'v'},
51+
{"version", required_argument, NULL, 'v'},
5252
{"direction", optional_argument, NULL, 'd'},
5353
{0, 0, NULL, 0}};
5454

@@ -420,9 +420,9 @@ static void parse_tcp(char *file, int (*proc)(int, char *))
420420
}
421421

422422
/* Validate map filepath */
423-
int get_bpf_map_file(const char *ifname, const char *map_name, char *map_file)
423+
int get_bpf_map_file(const char *ifname, const char *version, const char *map_name, char *map_file)
424424
{
425-
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s", map_base_dir, ifname, map_name);
425+
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s/%s/%s", map_base_dir, ifname, prog_name, version, map_name);
426426
log_info("map path filename %s", map_file);
427427
struct stat st = {0};
428428
if (stat(map_file, &st) != 0)
@@ -463,6 +463,7 @@ int main(int argc, char **argv)
463463
char ports[PORT_LENGTH];
464464
char map_file[MAP_PATH_SIZE];
465465
char ifname[IF_NAMESIZE];
466+
char *version = NULL;
466467

467468
verbosity = LOG_INFO;
468469

@@ -484,9 +485,8 @@ int main(int argc, char **argv)
484485
return EXIT_FAILURE;
485486
}
486487
break;
487-
case 'v':
488-
if (optarg)
489-
verbosity = (int)(strtoi(optarg, 10));
488+
case 'v': /* version variable passed by l3afd */
489+
version = optarg;
490490
break;
491491
case 'd':
492492
/* Not honoured as of now */
@@ -501,7 +501,7 @@ int main(int argc, char **argv)
501501
setrlimit(RLIMIT_MEMLOCK, &r);
502502

503503
memset(map_file, '\0', MAP_PATH_SIZE);
504-
if (get_bpf_map_file(ifname, conn_count_map_name, map_file) < 0)
504+
if (get_bpf_map_file(ifname, version, conn_count_map_name, map_file) < 0)
505505
{
506506
log_err("ERROR: map file path (%s) doesn't exists\n", map_file);
507507
close_log_file();
@@ -514,7 +514,7 @@ int main(int argc, char **argv)
514514
strerror(errno), errno);
515515
}
516516
memset(map_file, '\0', MAP_PATH_SIZE);
517-
if (get_bpf_map_file(ifname, tcp_conns_map_name, map_file) < 0)
517+
if (get_bpf_map_file(ifname, version, tcp_conns_map_name, map_file) < 0)
518518
{
519519
close_log_file();
520520
close_all_fds();
@@ -528,7 +528,7 @@ int main(int argc, char **argv)
528528
strerror(errno), errno);
529529
}
530530
memset(map_file, '\0', MAP_PATH_SIZE);
531-
if (get_bpf_map_file(ifname, conn_info_map_name, map_file) < 0)
531+
if (get_bpf_map_file(ifname, version, conn_info_map_name, map_file) < 0)
532532
{
533533
close_log_file();
534534
close_all_fds();

connection-limit/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const char *conn_count_map_name = "cl_conn_count";
1818
static const char *tcp_conns_map_name = "cl_tcp_conns";
1919
static const char *conn_info_map_name = "cl_conn_info";
2020
static const char map_base_dir[] = "/sys/fs/bpf";
21+
static const char *prog_name = "connection-limit";
2122

2223
/* Port separator */
2324
const char delim[] = ",";

ipfix-flow-exporter/bpf_ipfix_egress_user.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void sig_handler(int signo)
3333
exit(EXIT_SUCCESS);
3434
}
3535

36-
int populate_egress_fds(void) {
36+
int populate_egress_fds(const char *version) {
3737
char map_file[MAP_PATH_SIZE];
38-
if (get_bpf_map_file(if_name, egress_bpf_map, map_file) < 0) {
38+
if (get_bpf_map_file(if_name, version, egress_bpf_map, map_file) < 0) {
3939
fprintf(stderr, "ERROR: map file path (%s) doesn't exists", map_file);
4040
return EXIT_FAILURE;
4141
}
@@ -47,7 +47,7 @@ int populate_egress_fds(void) {
4747
return EXIT_FAILURE;
4848
}
4949

50-
if (get_bpf_map_file(if_name, last_egress_bpf_map, map_file) < 0) {
50+
if (get_bpf_map_file(if_name, version, last_egress_bpf_map, map_file) < 0) {
5151
fprintf(stderr, "ERROR: map file path (%s) doesn't exists", map_file);
5252
return EXIT_FAILURE;
5353
}
@@ -66,6 +66,7 @@ int main(int argc, char **argv)
6666
verbosity = LOG_INFO;
6767
long flow_timeout = 0;
6868
char *eptr;
69+
char *version;
6970
/* Parse commands line args */
7071
while ((opt = getopt_long(argc, argv, "hq",
7172
long_options, &long_index)) != -1) {
@@ -101,7 +102,11 @@ int main(int argc, char **argv)
101102
remote_port = (int)(strtol(optarg, &eptr, 10));
102103
break;
103104
case 'd':
104-
break;
105+
break;
106+
case 'v':
107+
if(optarg)
108+
version = optarg;
109+
break;
105110
case 'h':
106111
default:
107112
usage(argv, __doc__);
@@ -116,7 +121,7 @@ int main(int argc, char **argv)
116121
return EXIT_FAILURE;
117122
}
118123

119-
if (populate_egress_fds() == EXIT_FAILURE) {
124+
if (populate_egress_fds(version) == EXIT_FAILURE) {
120125
fprintf(stderr, "ERR: Fetching TC EGRESS maps failed\n");
121126
close_logfile();
122127
close_egress_fds();

ipfix-flow-exporter/bpf_ipfix_ingress_user.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ void sig_handler(int signo)
3232
exit(EXIT_SUCCESS);
3333
}
3434

35-
int populate_ingress_fds(void) {
35+
int populate_ingress_fds(const char *version) {
3636
char map_file[MAP_PATH_SIZE];
37-
if (get_bpf_map_file(if_name, ingress_bpf_map, map_file) < 0) {
37+
if (get_bpf_map_file(if_name, version, ingress_bpf_map, map_file) < 0) {
3838
fprintf(stderr, "ERROR: map file path (%s) doesn't exists", map_file);
3939
return EXIT_FAILURE;
4040
}
@@ -45,7 +45,7 @@ int populate_ingress_fds(void) {
4545
return EXIT_FAILURE;
4646
}
4747

48-
if (get_bpf_map_file(if_name, last_ingress_bpf_map, map_file) < 0) {
48+
if (get_bpf_map_file(if_name, version, last_ingress_bpf_map, map_file) < 0) {
4949
fprintf(stderr, "ERROR: map file path (%s) doesn't exists", map_file);
5050
return EXIT_FAILURE;
5151
}
@@ -65,6 +65,7 @@ int main(int argc, char **argv)
6565
verbosity = LOG_INFO;
6666
long flow_timeout = 0;
6767
char *eptr;
68+
char *version;
6869

6970
/* Parse commands line args */
7071
while ((opt = getopt_long(argc, argv, "hq",
@@ -100,9 +101,12 @@ int main(int argc, char **argv)
100101
if(optarg)
101102
remote_port = (int)(strtol(optarg, &eptr, 10));
102103
break;
104+
case 'v' :
105+
if(optarg)
106+
version = optarg;
103107
case 'd':
104108
/* This option is to have consistancy across NFs */
105-
break;
109+
break;
106110
case 'h':
107111
default:
108112
usage(argv, __doc__);
@@ -117,7 +121,7 @@ int main(int argc, char **argv)
117121
return EXIT_FAILURE;
118122
}
119123

120-
if (populate_ingress_fds() == EXIT_FAILURE) {
124+
if (populate_ingress_fds(version) == EXIT_FAILURE) {
121125
fprintf(stderr, "ERR: Fetching TC INGRESS maps failed\n");
122126
close_logfile();
123127
close_ingress_fds();

ipfix-flow-exporter/bpf_ipfix_user.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const struct option long_options[] = {
3131
{"collector_ip", required_argument, NULL, 'c' },
3232
{"direction", required_argument, NULL, 'd' },
3333
{"collector_port", required_argument, NULL, 'p' },
34+
{"version", required_argument, NULL, 'v'},
3435
{"flow-timeout", optional_argument, NULL, 't' },
3536
{"verbose (allowed 0-4, 0-NO_LOG,1-LOG_DEBUG,2-LOG_INFO,3-LOG_WARN,4-LOG_ERR,5-LOG_CRIT)", optional_argument, NULL, 'q' },
3637
{0, 0, NULL, 0 }
@@ -382,9 +383,9 @@ int get_length(const char *str)
382383
}
383384

384385
/* Map filepath is created by l3afd */
385-
int get_bpf_map_file(const char *ifname, const char *map_name, char *map_file)
386+
int get_bpf_map_file(const char *ifname, const char *version, const char *map_name, char *map_file)
386387
{
387-
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s", map_base_dir, ifname, map_name);
388+
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s/%s/%s", map_base_dir, ifname, prog_name, version, map_name);
388389
log_info("map path filename %s", map_file);
389390
struct stat st = {0};
390391
if (stat(map_file, &st) != 0) {

ipfix-flow-exporter/bpf_ipfix_user.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern const char* ipfix_egress_jmp_table;
4040
extern const char* ingress_dir;
4141
extern const char* egress_dir;
4242
static const char map_base_dir[] = "/sys/fs/bpf/tc/globals";
43-
43+
static const char *prog_name = "ipfix-flow-exporter";
4444
extern bool chain;
4545
extern char *remote_ip, *bpf_map_file_path, *tc_cmd;
4646
extern int flow_timeout, remote_port, bpf_map_fd;
@@ -89,17 +89,17 @@ int validate_str(const char *str);
8989

9090
void sig_handler(int signo);
9191

92-
int populate_egress_fds(void);
92+
int populate_egress_fds(const char *version);
9393

94-
int populate_ingress_fds(void);
94+
int populate_ingress_fds(const char *version);
9595

9696
void cpy(char *src,char *des);
9797

9898
bool validate_map_name(const char *path);
9999

100100
bool validate_map(const char* input);
101101

102-
int get_bpf_map_file(const char *ifname, const char *map_name, char *map_file);
102+
int get_bpf_map_file(const char *ifname, const char *version, const char *map_name, char *map_file);
103103

104104
void close_fd(int fd);
105105
void close_ingress_fds(void);

traffic-mirroring/mirroring.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ static const struct option long_options[] = {
301301
{"help", no_argument, NULL, 'h'},
302302
{"iface", required_argument, NULL, 'i'},
303303
{"redirect-to", required_argument, NULL, 'e'},
304+
{"version", required_argument, NULL, 'v'},
304305
/* HINT assign: optional_arguments with '=' */
305306
{ "direction", optional_argument, NULL, 't' },
306307
{ "src-address", optional_argument, NULL, 's' },
@@ -667,9 +668,9 @@ static void update_proto(int map_fd, char *protocols)
667668
}
668669

669670
/* validate map file path */
670-
int get_bpf_map_file(const char *ifname, const char *map_name, char *map_file)
671+
int get_bpf_map_file(const char *ifname, const char *version, const char *map_name, char *map_file)
671672
{
672-
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s", map_base_dir, ifname, map_name);
673+
snprintf(map_file, MAP_PATH_SIZE, "%s/%s/%s/%s/%s", map_base_dir, ifname, prog_name, version, map_name);
673674
log_info("map path filename %s", map_file);
674675
struct stat st = {0};
675676
if (stat(map_file, &st) != 0)
@@ -700,6 +701,7 @@ int main(int argc, char **argv)
700701
int slen = 0, dlen = 0, tmplen = 0, glen = 0;
701702
int ret = EXIT_SUCCESS;
702703
char map_file[MAP_PATH_SIZE];
704+
char *version;
703705

704706
memset(ifname, 0, IF_NAMESIZE); /* Can be used uninitialized */
705707
fprintf(stdout, "DEFAULT_LOGFILE is %s\n", DEFAULT_LOGFILE);
@@ -839,6 +841,9 @@ int main(int argc, char **argv)
839841
case 'q':
840842
verbose = 0;
841843
break;
844+
case 'v':
845+
if(optarg)
846+
version = optarg;
842847
case 'h':
843848
default:
844849
usage(argv);
@@ -861,7 +866,7 @@ int main(int argc, char **argv)
861866
fflush(info);
862867

863868
memset(map_file, '\0', MAP_PATH_SIZE);
864-
if (get_bpf_map_file(ifname, redirect_mapfile, map_file) < 0)
869+
if (get_bpf_map_file(ifname, version, redirect_mapfile, map_file) < 0)
865870
{
866871
log_err("ERROR: map file path (%s) doesn't exists", map_file);
867872
cleanup();
@@ -880,7 +885,7 @@ int main(int argc, char **argv)
880885
if (strcmp(direction, INGRESS) == 0)
881886
{
882887
memset(map_file, '\0', MAP_PATH_SIZE);
883-
if (get_bpf_map_file(ifname, src_mapfile, map_file) < 0)
888+
if (get_bpf_map_file(ifname, version, src_mapfile, map_file) < 0)
884889
{
885890
log_err("ERROR: map file path (%s) doesn't exists", map_file);
886891
cleanup();
@@ -896,7 +901,7 @@ int main(int argc, char **argv)
896901
ret = EXIT_FAILURE;
897902
}
898903
memset(map_file, '\0', MAP_PATH_SIZE);
899-
if (get_bpf_map_file(ifname, ingress_src_port_mapfile, map_file) < 0)
904+
if (get_bpf_map_file(ifname, version, ingress_src_port_mapfile, map_file) < 0)
900905
{
901906
log_err("ERROR: map file path (%s) doesn't exists", map_file);
902907
cleanup();
@@ -912,7 +917,7 @@ int main(int argc, char **argv)
912917
ret = EXIT_FAILURE;
913918
}
914919
memset(map_file, '\0', MAP_PATH_SIZE);
915-
if (get_bpf_map_file(ifname, ingress_dst_port_mapfile, map_file) < 0)
920+
if (get_bpf_map_file(ifname, version, ingress_dst_port_mapfile, map_file) < 0)
916921
{
917922
log_err("ERROR: map file path (%s) doesn't exists", map_file);
918923
cleanup();
@@ -927,7 +932,7 @@ int main(int argc, char **argv)
927932
ret = EXIT_FAILURE;
928933
}
929934
memset(map_file, '\0', MAP_PATH_SIZE);
930-
if (get_bpf_map_file(ifname, ingress_proto_mapfile, map_file) < 0)
935+
if (get_bpf_map_file(ifname, version, ingress_proto_mapfile, map_file) < 0)
931936
{
932937
log_err("ERROR: map file path (%s) doesn't exists", map_file);
933938
cleanup();
@@ -943,7 +948,7 @@ int main(int argc, char **argv)
943948
ret = EXIT_FAILURE;
944949
}
945950
memset(map_file, '\0', MAP_PATH_SIZE);
946-
if (get_bpf_map_file(ifname, ingress_any_mapfile, map_file) < 0)
951+
if (get_bpf_map_file(ifname, version, ingress_any_mapfile, map_file) < 0)
947952
{
948953
log_err("ERROR: map file path (%s) doesn't exists", map_file);
949954
cleanup();
@@ -962,7 +967,7 @@ int main(int argc, char **argv)
962967
else if (strcmp(direction, EGRESS) == 0)
963968
{
964969
memset(map_file, '\0', MAP_PATH_SIZE);
965-
if (get_bpf_map_file(ifname, dst_mapfile, map_file) < 0)
970+
if (get_bpf_map_file(ifname, version, dst_mapfile, map_file) < 0)
966971
{
967972
log_err("ERROR: map file path (%s) doesn't exists", map_file);
968973
cleanup();
@@ -978,7 +983,7 @@ int main(int argc, char **argv)
978983
}
979984

980985
memset(map_file, '\0', MAP_PATH_SIZE);
981-
if (get_bpf_map_file(ifname, egress_src_port_mapfile, map_file) < 0)
986+
if (get_bpf_map_file(ifname, version, egress_src_port_mapfile, map_file) < 0)
982987
{
983988
log_err("ERROR: map file path (%s) doesn't exists", map_file);
984989
cleanup();
@@ -994,7 +999,7 @@ int main(int argc, char **argv)
994999
ret = EXIT_FAILURE;
9951000
}
9961001
memset(map_file, '\0', MAP_PATH_SIZE);
997-
if (get_bpf_map_file(ifname, egress_dst_port_mapfile, map_file) < 0)
1002+
if (get_bpf_map_file(ifname, version, egress_dst_port_mapfile, map_file) < 0)
9981003
{
9991004
log_err("ERROR: map file path (%s) doesn't exists", map_file);
10001005
cleanup();
@@ -1009,7 +1014,7 @@ int main(int argc, char **argv)
10091014
ret = EXIT_FAILURE;
10101015
}
10111016
memset(map_file, '\0', MAP_PATH_SIZE);
1012-
if (get_bpf_map_file(ifname, egress_proto_mapfile, map_file) < 0)
1017+
if (get_bpf_map_file(ifname, version, egress_proto_mapfile, map_file) < 0)
10131018
{
10141019
log_err("ERROR: map file path (%s) doesn't exists", map_file);
10151020
cleanup();
@@ -1024,7 +1029,7 @@ int main(int argc, char **argv)
10241029
ret = EXIT_FAILURE;
10251030
}
10261031
memset(map_file, '\0', MAP_PATH_SIZE);
1027-
if (get_bpf_map_file(ifname, egress_any_mapfile, map_file) < 0)
1032+
if (get_bpf_map_file(ifname, version, egress_any_mapfile, map_file) < 0)
10281033
{
10291034
log_err("ERROR: map file path (%s) doesn't exists", map_file);
10301035
cleanup();

traffic-mirroring/mirroring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static const char *ingress_any_mapfile = "ingress_any";
6666
static const char *egress_any_mapfile = "egress_any";
6767
static const char map_base_dir[] = "/sys/fs/bpf/tc/globals";
6868
static int verbose = 1;
69+
static const char *prog_name = "traffic-mirroring";
6970

7071
static bool validate_ifname(const char* input_ifname, char *output_ifname);
7172
static bool validate_address(char* input_address, network_addr_t output_address[], int *count);

0 commit comments

Comments
 (0)