@@ -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 ();
0 commit comments