Commit 59188589 authored by Maciej Lipinski's avatar Maciej Lipinski Committed by Adam Wujek

rtu_stat: added possibility to specify VID when adding MAC to RTU Table

parent d8bce438
...@@ -25,6 +25,9 @@ struct rtu_addr { ...@@ -25,6 +25,9 @@ struct rtu_addr {
#define RTU_ENTRY_TYPE_DYNAMIC 1 #define RTU_ENTRY_TYPE_DYNAMIC 1
#define RTU_ENTRY_TYPE_STATIC 0 #define RTU_ENTRY_TYPE_STATIC 0
/* When adding MAC entry, the Default VID is 0x0 */
#define RTU_ENTRY_VID_DEFAULT 0
/* helper to verify correctness of a rtu type */ /* helper to verify correctness of a rtu type */
static inline int rtu_check_type(int type) static inline int rtu_check_type(int type)
{ {
......
...@@ -52,11 +52,11 @@ int rtudexp_clear_entries(int port, int type) ...@@ -52,11 +52,11 @@ int rtudexp_clear_entries(int port, int type)
return (ret < 0) ? ret : val; return (ret < 0) ? ret : val;
} }
int rtudexp_add_entry(const char *mac, int port_mask, int type) int rtudexp_add_entry(const char *mac, int port_mask, int type, int vid)
{ {
int val, ret; int val, ret;
ret = minipc_call(rtud_ch, MINIPC_TIMEOUT, &rtud_export_add_entry, ret = minipc_call(rtud_ch, MINIPC_TIMEOUT, &rtud_export_add_entry,
&val, mac, port_mask, type); &val, mac, port_mask, type, vid);
return (ret < 0) ? ret : val; return (ret < 0) ? ret : val;
} }
...@@ -145,13 +145,20 @@ void show_help(char *prgname) ...@@ -145,13 +145,20 @@ void show_help(char *prgname)
" MAC address on a given port mask with\n" " MAC address on a given port mask with\n"
" an optional type (default %d-static)\n", " an optional type (default %d-static)\n",
RTU_ENTRY_TYPE_STATIC); RTU_ENTRY_TYPE_STATIC);
fprintf(stderr, " add <mac> <port> [<type>]: Add entry for a specific MAC address with an\n" fprintf(stderr, " add <mac> <port> [<type> <VID>]: Add entry for a specific MAC address with an\n"
" optional type (default %d-static)\n", " optional type (default %d-static) and VID (default %d);\n"
RTU_ENTRY_TYPE_STATIC); " if VID is specified, the type also has to be specified;\n"
fprintf(stderr, " add mask <mac> <port_mask> [<type>]: Add an entry for a specific \n" " in order to add MAC to a VID, this VID must exist in the\n"
" VLAN Table\n",
RTU_ENTRY_TYPE_STATIC, RTU_ENTRY_VID_DEFAULT);
fprintf(stderr, " add mask <mac> <port_mask> [<type> <VID>]: Add an entry for a specific \n"
" MAC address and multiple ports with\n" " MAC address and multiple ports with\n"
" an optional type (default %d-static)\n", " an optional type (default %d-static)\n"
RTU_ENTRY_TYPE_STATIC); " and VID (default %d); if VID is specified,\n"
" type also has to be specified;in order to\n"
" add MAC to a VID, this VID must exist in the\n"
" VLAN Table\n",
RTU_ENTRY_TYPE_STATIC, RTU_ENTRY_VID_DEFAULT);
fprintf(stderr, " learning: Read status of learning process in RTU\n"); fprintf(stderr, " learning: Read status of learning process in RTU\n");
fprintf(stderr, " learning <enable|disable> [<port>]: Enable/disable learning process in RTU\n" fprintf(stderr, " learning <enable|disable> [<port>]: Enable/disable learning process in RTU\n"
" for optional port, otherwise for all\n" " for optional port, otherwise for all\n"
...@@ -404,6 +411,7 @@ int main(int argc, char **argv) ...@@ -404,6 +411,7 @@ int main(int argc, char **argv)
int n_wait = 0; int n_wait = 0;
int ret; int ret;
int type; int type;
int vid;
int enable; int enable;
uint32_t mask; uint32_t mask;
...@@ -516,11 +524,11 @@ int main(int argc, char **argv) ...@@ -516,11 +524,11 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
isok = 1; isok = 1;
/* ****************** add mask <mac> <port_mask> [<type>] ****************** */ /* ****************** add mask <mac> <port_mask> [<type>, <VID>] ************ */
} else if (argc >= 5 } else if (argc >= 5
&& !strcmp(argv[1], "add") && !strcmp(argv[1], "add")
&& !strcmp(argv[2], "mask")) { && !strcmp(argv[2], "mask")) {
/* rtu_stat add mask <mac> <port_mask> [<type>] */ /* rtu_stat add mask <mac> <port_mask> [<type>, <VID>] */
i = read_port_mask(argv[4], nports); i = read_port_mask(argv[4], nports);
/* interface number 1..18, CPU is 19 */ /* interface number 1..18, CPU is 19 */
if (i < 0) { if (i < 0) {
...@@ -536,9 +544,15 @@ int main(int argc, char **argv) ...@@ -536,9 +544,15 @@ int main(int argc, char **argv)
fprintf(stderr, "rtu_stat: Unknown type %d\n", type); fprintf(stderr, "rtu_stat: Unknown type %d\n", type);
exit(1); exit(1);
} }
vid = atoidef(argc, argv, 6, RTU_ENTRY_VID_DEFAULT);
if (0 > vid || vid > 0xFFF) {
fprintf(stderr, "rtu_stat: Incorrect VID %d\n", vid);
exit(1);
}
ret = rtudexp_add_entry(argv[3], /* MAC */ ret = rtudexp_add_entry(argv[3], /* MAC */
i, /* port mask */ i, /* port mask */
type /* type */ type, /* type */
vid /* VID */
); );
if (ret > 0) if (ret > 0)
printf("Added %d entries for port mask 0x%x\n", printf("Added %d entries for port mask 0x%x\n",
...@@ -548,10 +562,10 @@ int main(int argc, char **argv) ...@@ -548,10 +562,10 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
isok = 1; isok = 1;
/* ****************** add <mac> <port> [<type>] **************************** */ /* ****************** add <mac> <port> [<type>, <VID>] ********************** */
} else if (argc >= 4 } else if (argc >= 4
&& !strcmp(argv[1], "add")) { && !strcmp(argv[1], "add")) {
/* rtu_stat add <mac> <port> [<type>] */ /* rtu_stat add <mac> <port> [<type>, <VID>] */
i = read_port(argv[3], nports); i = read_port(argv[3], nports);
/* interface number 1..18, CPU is 19 */ /* interface number 1..18, CPU is 19 */
if (i < 0) { if (i < 0) {
...@@ -567,9 +581,15 @@ int main(int argc, char **argv) ...@@ -567,9 +581,15 @@ int main(int argc, char **argv)
fprintf(stderr, "rtu_stat: Unknown type %d\n", type); fprintf(stderr, "rtu_stat: Unknown type %d\n", type);
exit(1); exit(1);
} }
vid = atoidef(argc, argv, 5, RTU_ENTRY_VID_DEFAULT);
if (0 > vid || vid > 0xFFF) {
fprintf(stderr, "rtu_stat: Incorrect VID %d\n", vid);
exit(1);
}
ret = rtudexp_add_entry(argv[2], /* MAC */ ret = rtudexp_add_entry(argv[2], /* MAC */
1 << (i - 1), /* port mask */ 1 << (i - 1), /* port mask */
type /* type */ type, /* type */
vid /* VID */
); );
if (ret > 0) if (ret > 0)
printf("Added %d entries for port %d (wri%d)\n", printf("Added %d entries for port %d (wri%d)\n",
......
...@@ -81,12 +81,14 @@ int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret) ...@@ -81,12 +81,14 @@ int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret)
char *mac; char *mac;
uint32_t port_mask; uint32_t port_mask;
int type; int type;
int vid;
int *p_ret = (int *)ret; /* force pointed to int type */ int *p_ret = (int *)ret; /* force pointed to int type */
mac = (char *)args; mac = (char *)args;
args = minipc_get_next_arg(args, pd->args[0]); args = minipc_get_next_arg(args, pd->args[0]);
port_mask = (int)args[0]; port_mask = (int)args[0];
type = (int)args[1]; type = (int)args[1];
vid = (int)args[2];
if (mac_verify(mac)) { if (mac_verify(mac)) {
pr_error("%s is an invalid MAC format (XX:XX:XX:XX:XX:XX)\n", pr_error("%s is an invalid MAC format (XX:XX:XX:XX:XX:XX)\n",
...@@ -105,11 +107,15 @@ int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret) ...@@ -105,11 +107,15 @@ int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret)
*p_ret = -1; *p_ret = -1;
return *p_ret; return *p_ret;
} }
if (0 > vid || vid > 0xFFF) { /* FID must be between 0x0 and 0xFFF*/
pr_error("Wrong FID value 0x%x\n", vid);
*p_ret = -1;
return *p_ret;
}
pr_debug("Request to add an entry with port mask 0x%x, MAC: %s, " pr_debug("Request to add an entry with port mask 0x%x, MAC: %s, "
"type:%s\n", port_mask, mac_to_string(mac_tmp), "type:%s\n", port_mask, mac_to_string(mac_tmp),
rtu_type_to_str(type)); rtu_type_to_str(type));
*p_ret = rtu_fd_create_entry(mac_tmp, 0, port_mask, type, *p_ret = rtu_fd_create_entry(mac_tmp, vid, port_mask, type,
OVERRIDE_EXISTING); OVERRIDE_EXISTING);
return *p_ret; return *p_ret;
} }
......
...@@ -62,6 +62,7 @@ struct minipc_pd rtud_export_add_entry = { ...@@ -62,6 +62,7 @@ struct minipc_pd rtud_export_add_entry = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *), /* MAC */ MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *), /* MAC */
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* port mask */ MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* port mask */
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* type */ MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* type */
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* VID */
MINIPC_ARG_END, MINIPC_ARG_END,
}, },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment