if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"does not exist"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to determine driver of interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to determine driver of interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
if(strcasestr(cmd_result,"bridge")){
bridge_device=SWITCH_TRUE;
}
switch_safe_free(cmd_result);
}
/* This clears routes and puts the interface in a DOWN state
which then requires us to bring it back up. This helps to
check for issues to make sure we can actually bring it back
is wrong, but not bring it back up. This helps us check
that condition. */
memset(cmd,0,256);
sprintf(cmd,"ifdown %s 2>&1",cur_int->name);
snprintf(cmd,256,"ifdown %s 2>&1",cur_int->name);
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"does not exist"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
/* We do not want to have an IP address conflict while starting
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"does not exist"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
if(vlan_device==SWITCH_FALSE){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
}
switch_safe_free(cmd_result);
/* If speed and duplex are specified, set them and disable autoneg */
/* We do not want to have an IP address conflict while starting
this node, so we flush the addresses. If this is a vlan, we
will not be able to reference the dev if it is down. We
expect the act of taking it down to remove the IPs. */
memset(cmd,0,256);
sprintf(cmd,"ethtool -s %s speed %s duplex %s autoneg off 2>&1",cur_int->name,cur_int->speed,cur_int->duplex);
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"Cannot set new settings"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set speed and duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set speed and duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"does not exist"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
}else{
if(!switch_strlen_zero(cur_int->duplex)){
/* Set the duplex on the interface if specified */
snprintf(cmd,256,"ethtool -s %s speed %s duplex %s autoneg off 2>&1",cur_int->name,cur_int->speed,cur_int->duplex);
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"Cannot set new settings"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set speed and duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set speed and duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"Cannot set new settings"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set speed on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set speed on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
}else{
if(!switch_strlen_zero(cur_int->duplex)){
/* Set the duplex on the interface if specified */
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"Cannot set new settings"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set duplex on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"Cannot set new settings"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to set speed on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to set speed on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
}
}
/* Now we bring the interface back up to ensure we *can* bring
it up. We turn off ARP so that when we assign IPs to it, we
do not immediately start talking over it. */
memset(cmd,0,256);
sprintf(cmd,"ip link set %s up arp off 2>&1",cur_int->name);
if(vlan_device==SWITCH_TRUE){
snprintf(cmd,256,"ifup %s && sleep 1 && ip link set %s arp off 2>&1",cur_int->name,cur_int->name);
}else{
snprintf(cmd,256,"ip link set %s up arp off 2>&1",cur_int->name);
}
if(execute_command(cmd,&cmd_result)!=SWITCH_STATUS_SUCCESS||!cmd_result||(cmd_result&&strstr(cmd_result,"does not exist"))){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to control interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to query interface '%s' for duplex and speed: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to query interface '%s' for duplex and speed: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' duplex not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: interface '%s' duplex not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to query interface '%s' for duplex and speed: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: unable to query interface '%s' for duplex and speed: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' speed not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: interface '%s' speed not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' duplex not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: interface '%s' duplex not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' speed not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
fprintf(stderr,"HAC: interface '%s' speed not set correctly: %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unkown error":cmd_result));
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
}
switch_safe_free(cmd_result);
}
switch_safe_free(cmd_result);
cur_int=cur_int->next;
}
/* If we get here, we are fairly confident all the interfaces are
sprintf(cmd,"ip route del %s via %s dev %s metric %s 2>&1",cur->destination,cur->gateway,cur->dev,(switch_strlen_zero(cur->metric)?"0":cur->metric));
snprintf(cmd,256,"ip route del %s via %s dev %s metric %s 2>&1",cur->destination,cur->gateway,cur->dev,(switch_strlen_zero(cur->metric)?"0":cur->metric));