switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' does not exist\n",cur_int->name);
fprintf(stderr,"HAC: interface '%s' does not exist\n",cur_int->name);
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
cur_int=cur_int->next;
}
/* After we know they exist, then take controll over them. */
cur_int=config.network.interfaces;
while(cur_int!=NULL){
/* 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
up. Sometimes we can take the interface down when something
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);
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;
}
switch_safe_free(cmd_result);
/* If speed and duplex are specified, set them and disable autoneg */
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));
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 */
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);
}
}
/* 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(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);
/* Run an internal test on the interface to help check to see
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' loss of carrier detected\n",cur_int->name);
fprintf(stderr,"HAC: interface '%s' loss of carrier detected\n",cur_int->name);
}elseif(cmd_result&&strstr(cmd_result,"DOWN")){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' is down\n",cur_int->name);
fprintf(stderr,"HAC: interface '%s' is down\n",cur_int->name);
}else{
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to check carrier status on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unknown error":cmd_result));
fprintf(stderr,"HAC: unable to check carrier status on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unknown error":cmd_result));
}
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
/* Set the duplex on the interface if specified */
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: 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);
cur_int=cur_int->next;
}
/* If we get here, we are fairly confident all the interfaces are
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' loss of carrier detected\n",cur_int->name);
fprintf(stderr,"HAC: interface '%s' loss of carrier detected\n",cur_int->name);
}elseif(cmd_result&&strstr(cmd_result,"DOWN")){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: interface '%s' is down\n",cur_int->name);
fprintf(stderr,"HAC: interface '%s' is down\n",cur_int->name);
}else{
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_CRIT,"HAC: unable to check carrier status on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unknown error":cmd_result));
fprintf(stderr,"HAC: unable to check carrier status on interface '%s': %s\n",cur_int->name,(switch_strlen_zero(cmd_result)?"unknown error":cmd_result));
}
switch_safe_free(cmd_result);
returnSWITCH_STATUS_FALSE;
}
switch_safe_free(cmd_result);
/* Run an internal test on the interface to help check to see