Commit 449c5c89 authored by Jean-Claude BAU's avatar Jean-Claude BAU Committed by Grzegorz Daniluk

Clear VLAN configuration in case of error

parent f7a01f92
...@@ -458,6 +458,8 @@ if [ -n "$CONFIG_PPSGEN_FORCE" ]; then ...@@ -458,6 +458,8 @@ if [ -n "$CONFIG_PPSGEN_FORCE" ]; then
globals[forcePpsGen]="$CONFIG_PPSGEN_FORCE" globals[forcePpsGen]="$CONFIG_PPSGEN_FORCE"
fi fi
vlan_error_detected=0 # If a VLAN error is detected, then VLAN are disabled on all ports
for i_port in {01..18}; do # scan all the physical ports for i_port in {01..18}; do # scan all the physical ports
port_vn="port${i_port}" port_vn="port${i_port}"
...@@ -561,9 +563,8 @@ for i_port in {01..18}; do # scan all the physical ports ...@@ -561,9 +563,8 @@ for i_port in {01..18}; do # scan all the physical ports
# check port mode # check port mode
if [ "$port_mode_access" = "y" ]; then if [ "$port_mode_access" = "y" ]; then
if [ "$raw_config" != "y" ]; then [[ "$raw_config" != "y" ]] && port_ptp_vid=$port_vid
port_ptp_vid=$port_vid
fi
# use "&> /dev/null" to avoid error when $ppsi_vlans # use "&> /dev/null" to avoid error when $ppsi_vlans
# is not a number # is not a number
if [ "$port_ptp_vid" -ge 0 ] &> /dev/null \ if [ "$port_ptp_vid" -ge 0 ] &> /dev/null \
...@@ -571,6 +572,7 @@ for i_port in {01..18}; do # scan all the physical ports ...@@ -571,6 +572,7 @@ for i_port in {01..18}; do # scan all the physical ports
v="$inst_vn[vlan]"; eval ${v}="$port_ptp_vid" v="$inst_vn[vlan]"; eval ${v}="$port_ptp_vid"
else else
echo "$script_name: Wrong value \"$port_ptp_vid\" in CONFIG_VLANS_PORT"$i_port"_PTP_VID" | tee $log_output echo "$script_name: Wrong value \"$port_ptp_vid\" in CONFIG_VLANS_PORT"$i_port"_PTP_VID" | tee $log_output
[[ "$raw_config" != "y" ]] && vlan_error_detected=1
continue; continue;
fi fi
fi fi
...@@ -588,6 +590,18 @@ for i_port in {01..18}; do # scan all the physical ports ...@@ -588,6 +590,18 @@ for i_port in {01..18}; do # scan all the physical ports
done # scan all the ppsi instances in a port done # scan all the ppsi instances in a port
done # scan all the physical ports done # scan all the physical ports
if [ "$vlan_error_detected" -ne "0" ] ; then
# VLAN error detected: Remove VLAN configuration on all ports
echo "$script_name: Wrong VLAN configurations. VLAN configuration removed on all ports." | tee $log_output
for i_port in {01..18}; do # scan all the physical ports
port_vn="port${i_port}"
for j_inst in {01..02}; do # scan all the ppsi instances for a given port
inst_vn="${port_vn}inst${j_inst}"
v="$inst_vn[vlan]";[[ -n "${!v}" ]] && unset ${v}
done
done
fi
if [ -v JSON_FORMAT ] ; then if [ -v JSON_FORMAT ] ; then
gen_ppsi_conf_json ${OUTPUT_FILE} ${PRE_FILE} gen_ppsi_conf_json ${OUTPUT_FILE} ${PRE_FILE}
else else
......
...@@ -83,10 +83,10 @@ static char *yes_no[] ={"no ", ...@@ -83,10 +83,10 @@ static char *yes_no[] ={"no ",
static unsigned long portmask; static unsigned long portmask;
static void set_p_pmode(int ep, int arg_mode); static void set_p_pmode(int ep, int arg_mode);
static void set_p_vid(int ep, char *arg_vid); static int set_p_vid(int ep, char *arg_vid);
static void set_p_prio(int ep, char *arg_prio); static int set_p_prio(int ep, char *arg_prio);
static void set_p_untag(int ep, int arg_untag); static void set_p_untag(int ep, int arg_untag);
static void set_hp_mask(char *mask_str); static int set_hp_mask(char *mask_str);
static int check_rtu(char *name, char *arg_val, int min, int max); static int check_rtu(char *name, char *arg_val, int min, int max);
static int check_rtu_prio(char *arg_val); static int check_rtu_prio(char *arg_val);
static int print_help(char *prgname); static int print_help(char *prgname);
...@@ -105,7 +105,7 @@ static int rtu_find_vlan(struct rtu_vlan_table_entry *rtu_vlan_entry, int vid, ...@@ -105,7 +105,7 @@ static int rtu_find_vlan(struct rtu_vlan_table_entry *rtu_vlan_entry, int vid,
int fid); int fid);
static int config_rtud(void); static int config_rtud(void);
static int read_dot_config(char *dot_config_file); static int read_dot_config(char *dot_config_file);
static void read_dot_config_vlans(int vlan_min, int vlan_max); static int read_dot_config_vlans(int vlan_min, int vlan_max);
struct rtu_vlan_table_entry *vlan_tab_shm; struct rtu_vlan_table_entry *vlan_tab_shm;
struct wrs_shm_head *rtu_port_shmem; struct wrs_shm_head *rtu_port_shmem;
...@@ -266,14 +266,16 @@ int main(int argc, char *argv[]) ...@@ -266,14 +266,16 @@ int main(int argc, char *argv[])
case OPT_P_PRIO: case OPT_P_PRIO:
/* priority value for port, forces fix_prio=1 */ /* priority value for port, forces fix_prio=1 */
iterate_ports(i, conf_pmask) { iterate_ports(i, conf_pmask) {
set_p_prio(i, optarg); if ( set_p_prio(i, optarg)<0 )
exit(1);
} }
break; break;
case OPT_P_VID: case OPT_P_VID:
/* VID for port */ /* VID for port */
iterate_ports(i, conf_pmask) { iterate_ports(i, conf_pmask) {
set_p_vid(i, optarg); if ( set_p_vid(i, optarg)<0 )
exit(1);
} }
break; break;
...@@ -333,7 +335,8 @@ int main(int argc, char *argv[]) ...@@ -333,7 +335,8 @@ int main(int argc, char *argv[])
set_rtu_vlan(-1, -1, -1, 0, -1, 1, 0); set_rtu_vlan(-1, -1, -1, 0, -1, 1, 0);
break; break;
case OPT_RTU_HP_MASK: case OPT_RTU_HP_MASK:
set_hp_mask(optarg); if ( set_hp_mask(optarg)<0 )
exit(1);
break; break;
/****************************************************/ /****************************************************/
/* Other settings */ /* Other settings */
...@@ -407,6 +410,7 @@ static char *trimWhitespace(char *str) ...@@ -407,6 +410,7 @@ static char *trimWhitespace(char *str)
return str; return str;
} }
static void set_p_pmode(int ep, int arg_mode) static void set_p_pmode(int ep, int arg_mode)
{ {
vlans[ep].pmode = arg_mode; vlans[ep].pmode = arg_mode;
...@@ -428,7 +432,7 @@ static void set_p_pmode(int ep, int arg_mode) ...@@ -428,7 +432,7 @@ static void set_p_pmode(int ep, int arg_mode)
set_p_untag(ep,(arg_mode == 0)); // apply default value set_p_untag(ep,(arg_mode == 0)); // apply default value
} }
static void set_p_vid(int ep, char *arg_vid) static int set_p_vid(int ep, char *arg_vid)
{ {
int vid; int vid;
char *endptr; char *endptr;
...@@ -440,13 +444,14 @@ static void set_p_vid(int ep, char *arg_vid) ...@@ -440,13 +444,14 @@ static void set_p_vid(int ep, char *arg_vid)
) { ) {
pr_error("invalid vid \"%s\" for port %d\n", pr_error("invalid vid \"%s\" for port %d\n",
arg_vid, ep + 1); arg_vid, ep + 1);
exit(1); return -1;
} }
vlans[ep].vid = vid; vlans[ep].vid = vid;
vlans[ep].valid_mask |= VALID_VID; vlans[ep].valid_mask |= VALID_VID;
return 0;
} }
static void set_p_prio(int ep, char *arg_prio) static int set_p_prio(int ep, char *arg_prio)
{ {
int prio; int prio;
char *endptr; char *endptr;
...@@ -460,7 +465,7 @@ static void set_p_prio(int ep, char *arg_prio) ...@@ -460,7 +465,7 @@ static void set_p_prio(int ep, char *arg_prio)
) { ) {
pr_error("invalid priority \"%s\" for port %d\n", pr_error("invalid priority \"%s\" for port %d\n",
arg_prio, ep + 1); arg_prio, ep + 1);
exit(1); return -1;
} }
/* prio was touched, so set VALID_PRIO */ /* prio was touched, so set VALID_PRIO */
vlans[ep].valid_mask |= VALID_PRIO; vlans[ep].valid_mask |= VALID_PRIO;
...@@ -471,6 +476,7 @@ static void set_p_prio(int ep, char *arg_prio) ...@@ -471,6 +476,7 @@ static void set_p_prio(int ep, char *arg_prio)
vlans[ep].prio_val = prio; vlans[ep].prio_val = prio;
vlans[ep].fix_prio = 1; vlans[ep].fix_prio = 1;
} }
return 0;
} }
static void set_p_untag(int ep, int arg_untag) static void set_p_untag(int ep, int arg_untag)
...@@ -479,7 +485,7 @@ static void set_p_untag(int ep, int arg_untag) ...@@ -479,7 +485,7 @@ static void set_p_untag(int ep, int arg_untag)
vlans[ep].valid_mask |= VALID_UNTAG; vlans[ep].valid_mask |= VALID_UNTAG;
} }
static void set_hp_mask(char *mask_str) static int set_hp_mask(char *mask_str)
{ {
int hp_mask; int hp_mask;
int val; int val;
...@@ -492,7 +498,7 @@ static void set_hp_mask(char *mask_str) ...@@ -492,7 +498,7 @@ static void set_hp_mask(char *mask_str)
|| *endptr != '\0' /* more chars after number in the string */ || *endptr != '\0' /* more chars after number in the string */
|| hp_mask >= (1 << 8)) { || hp_mask >= (1 << 8)) {
pr_error("Wrong HP mask %s\n", mask_str); pr_error("Wrong HP mask %s\n", mask_str);
exit(1); return -1;
} }
ret = minipc_call(rtud_ch, MINIPC_TIMEOUT, ret = minipc_call(rtud_ch, MINIPC_TIMEOUT,
...@@ -502,9 +508,9 @@ static void set_hp_mask(char *mask_str) ...@@ -502,9 +508,9 @@ static void set_hp_mask(char *mask_str)
if (ret < 0) { if (ret < 0) {
pr_error("failed to set HP mask 0x%x (%s), ret %d\n", pr_error("failed to set HP mask 0x%x (%s), ret %d\n",
hp_mask, mask_str, ret); hp_mask, mask_str, ret);
exit(1); return -2;
} }
return 0;
} }
static int check_rtu(char *name, char *arg_val, int min, int max) static int check_rtu(char *name, char *arg_val, int min, int max)
...@@ -1011,7 +1017,7 @@ static int read_dot_config(char *dot_config_file) ...@@ -1011,7 +1017,7 @@ static int read_dot_config(char *dot_config_file)
if (access(dot_config_file, R_OK)) { if (access(dot_config_file, R_OK)) {
pr_error("Unable to read dot-config file %s\n", pr_error("Unable to read dot-config file %s\n",
dot_config_file); dot_config_file);
return -1; goto error;
} }
line = libwr_cfg_read_file(dot_config_file); line = libwr_cfg_read_file(dot_config_file);
...@@ -1019,11 +1025,11 @@ static int read_dot_config(char *dot_config_file) ...@@ -1019,11 +1025,11 @@ static int read_dot_config(char *dot_config_file)
if (line == -1) { if (line == -1) {
pr_error("Unable to read dot-config file %s or error in " pr_error("Unable to read dot-config file %s or error in "
"line 1\n", dot_config_file); "line 1\n", dot_config_file);
return -1; goto error;
} else if (line) { } else if (line) {
pr_error("Error in dot-config file %s, error in line %d\n", pr_error("Error in dot-config file %s, error in line %d\n",
dot_config_file, -line); dot_config_file, -line);
return -1; goto error;
} }
ret = libwr_cfg_get("RTU_HP_MASK_ENABLE"); ret = libwr_cfg_get("RTU_HP_MASK_ENABLE");
...@@ -1035,10 +1041,11 @@ static int read_dot_config(char *dot_config_file) ...@@ -1035,10 +1041,11 @@ static int read_dot_config(char *dot_config_file)
if (ret) { if (ret) {
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Set RTU_HP_MASK_VAL %s\n", ret); printf("Set RTU_HP_MASK_VAL %s\n", ret);
set_hp_mask(ret); if ( set_hp_mask(ret)<0 )
goto error;
} else { } else {
pr_error("Unable to get RTU_HP_MASK_VAL\n"); pr_error("Unable to get RTU_HP_MASK_VAL\n");
exit(1); goto error;
} }
} }
...@@ -1058,7 +1065,7 @@ static int read_dot_config(char *dot_config_file) ...@@ -1058,7 +1065,7 @@ static int read_dot_config(char *dot_config_file)
/* Check if raw configuration is enabled */ /* Check if raw configuration is enabled */
ret = libwr_cfg_get("VLANS_RAW_PORT_CONFIG"); ret = libwr_cfg_get("VLANS_RAW_PORT_CONFIG");
rawPortConfig= ret && (!strcmp(ret, "y")); rawPortConfig= ret && (strcmp(ret, "y")==0);
for (port = 1; port <= NPORTS; port++) { for (port = 1; port <= NPORTS; port++) {
portmask = portmask | (1 << (port - 1)); portmask = portmask | (1 << (port - 1));
...@@ -1140,14 +1147,16 @@ static int read_dot_config(char *dot_config_file) ...@@ -1140,14 +1147,16 @@ static int read_dot_config(char *dot_config_file)
if (strPrio[0]!=0 ) { if (strPrio[0]!=0 ) {
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Found %s=%s\n", buff, strPrio); printf("Found %s=%s\n", buff, strPrio);
set_p_prio(port - 1, strPrio); if ( set_p_prio(port - 1, strPrio) <0 )
goto error_clear_vlans;
} else { } else {
if ( mode != QMODE_TRUNK ) { if ( mode != QMODE_TRUNK ) {
pr_error("Priority not defined for the port (%d) in" pr_error("Priority not defined for the port (%d) in"
" TRUNK mode!\n", port); " TRUNK mode!\n", port);
} }
if ( !rawPortConfig ) { if ( !rawPortConfig ) {
exit(1); /* Exit only if not raw port configuration */ /* Exit only if not raw port configuration */
goto error_clear_vlans;
} }
} }
} }
...@@ -1163,13 +1172,14 @@ static int read_dot_config(char *dot_config_file) ...@@ -1163,13 +1172,14 @@ static int read_dot_config(char *dot_config_file)
if (strVid[0]!=0 ) { if (strVid[0]!=0 ) {
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Found %s=%s\n", buff, strVid); printf("Found %s=%s\n", buff, strVid);
set_p_vid(port - 1, strVid); if ( set_p_vid(port - 1, strVid)<0 )
goto error_clear_vlans;
} else { } else {
if ( mode == QMODE_ACCESS ) if ( mode == QMODE_ACCESS )
pr_error("VID not defined for the port (%d) in" pr_error("VID not defined for the port (%d) in"
" ACCESS mode!\n", port); " ACCESS mode!\n", port);
if ( !rawPortConfig ) { if ( !rawPortConfig ) {
exit(1); /* Exit only if not raw port configuration */ goto error_clear_vlans; /* Exit only if not raw port configuration */
} }
} }
} }
...@@ -1183,21 +1193,31 @@ static int read_dot_config(char *dot_config_file) ...@@ -1183,21 +1193,31 @@ static int read_dot_config(char *dot_config_file)
printf("Vlan0 not configured: Using port mask based on" printf("Vlan0 not configured: Using port mask based on"
" configured port modes (0x%05x)\n", " configured port modes (0x%05x)\n",
vlan0_port_mask); vlan0_port_mask);
set_rtu_vlan(0, 0, vlan0_port_mask, -1, -1, 0, if ( set_rtu_vlan(0, 0, vlan0_port_mask, -1, -1, 0,
VALID_VID | VALID_FID | VALID_PMASK); VALID_VID | VALID_FID | VALID_PMASK) <0 )
goto error_clear_vlans;
} }
for (i = 0; dot_config_vlan_sets[i].name; i++) { for (i = 0; dot_config_vlan_sets[i].name; i++) {
ret = libwr_cfg_get(dot_config_vlan_sets[i].name); ret = libwr_cfg_get(dot_config_vlan_sets[i].name);
if (ret && !strcmp(ret, "y")) { if (ret && !strcmp(ret, "y")) {
read_dot_config_vlans(dot_config_vlan_sets[i].min, if ( read_dot_config_vlans(dot_config_vlan_sets[i].min,
dot_config_vlan_sets[i].max); dot_config_vlan_sets[i].max)<0 )
goto error_clear_vlans;
} }
} }
return 0; return 0;
error_clear_vlans:;
pr_error("Error detected during VLAN configuration. VLAN configuration cleared\n");
if (clear_all()==0)
default_vlan_config();
error:;
return -1;
} }
static void read_dot_config_vlans(int vlan_min, int vlan_max) static int read_dot_config_vlans(int vlan_min, int vlan_max)
{ {
int fid, prio, drop; int fid, prio, drop;
unsigned long pmask; unsigned long pmask;
...@@ -1216,7 +1236,7 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max) ...@@ -1216,7 +1236,7 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max)
fid = check_rtu("rtu vid", buff, RTU_FID_MIN, fid = check_rtu("rtu vid", buff, RTU_FID_MIN,
RTU_FID_MAX); RTU_FID_MAX);
if (fid < 0) if (fid < 0)
exit(1); return -1;
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Vlan %4d: Found fid=%d\n", printf("Vlan %4d: Found fid=%d\n",
vlan, fid); vlan, fid);
...@@ -1246,11 +1266,11 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max) ...@@ -1246,11 +1266,11 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max)
else { else {
pr_error("invalid drop parameter \"%s\" in " pr_error("invalid drop parameter \"%s\" in "
"VLANS_VLAN%04d\n", buff, vlan); "VLANS_VLAN%04d\n", buff, vlan);
exit(1); return -1;
} }
drop = check_rtu("rtu drop", buff, 0, 1); drop = check_rtu("rtu drop", buff, 0, 1);
if (drop < 0) if (drop < 0)
exit(1); return -1;
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Vlan %4d: Found drop=%d\n", printf("Vlan %4d: Found drop=%d\n",
vlan, drop); vlan, drop);
...@@ -1262,7 +1282,7 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max) ...@@ -1262,7 +1282,7 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max)
if (pmask < RTU_PMASK_MIN || pmask > RTU_PMASK_MAX) { if (pmask < RTU_PMASK_MIN || pmask > RTU_PMASK_MAX) {
pr_error("invalid port mask 0x%lx (\"%s\") for" pr_error("invalid port mask 0x%lx (\"%s\") for"
" vlan %4d\n", pmask, buff, vlan); " vlan %4d\n", pmask, buff, vlan);
exit(1); return -1;
} }
if (wrs_msg_level >= LOG_DEBUG) if (wrs_msg_level >= LOG_DEBUG)
printf("Vlan %4d: Port mask 0x%05lx\n", printf("Vlan %4d: Port mask 0x%05lx\n",
...@@ -1277,4 +1297,5 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max) ...@@ -1277,4 +1297,5 @@ static void read_dot_config_vlans(int vlan_min, int vlan_max)
vlan_flags); vlan_flags);
} }
} }
return 0;
} }
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