📄 ospfh_d.c
字号:
/* Initiate and start the OSPFH */
#include "ospfh.h"
#include "ospfh_patch.h"
struct ospf *
ospfh_init(struct thread_master *master)
{
struct ospf *new = malloc(sizeof (struct ospf));
new->nbrlist=list_new();
new->lsa_list=list_new();
new->ls_ack=list_new();
new->ls_ack_direct.ls_ack=list_new();
new->maxage_lsa=list_new();
new->t_write=NULL;
new->t_read=NULL;
new->t_maxage=NULL; /* MaxAge LSA remover timer. */
new->t_maxage_walker=NULL; /* MaxAge LSA checking timer. */
new->t_lsa_list=NULL;
new->t_ls_ack=NULL;
new->t_ls_feed_up_timer=NULL;
// new->t_ls_feed_down_timer=NULL;
//add a part 11.23
new->t_lsa_self=NULL;
new->lsa_self=NULL;
new->ls_upd_in = 0;
new->ls_upd_out = 0;
new->ls_ack_in = 0;
new->ls_ack_out = 0;
new->discarded = 0;
new->v_ls_ack=1;
new->v_ls_feed_up=5;
// new->v_ls_feed_down=10;
new->transmit_delay =OSPF_TRANSMIT_DELAY_DEFAULT;
new->retransmit_interval=OSPF_RETRANSMIT_INTERVAL_DEFAULT;
new->outbuf=ospf_fifo_new ();
new->rx_lsa_count=0;
new->lsa_originate_count=0;
new->mtu=OSPF_IF_MTU;
new->master=master;
new->conf_cmd[0].string="set self rc id";
new->conf_cmd[0].func=router_id_set;
new->conf_cmd[1].string="set ip address";
new->conf_cmd[1].func=ip_addr_set;
new->conf_cmd[2].string="set neighbor id";
new->conf_cmd[2].func=nbr_id_set;
new->conf_cmd[3].string="set speaker id";
new->conf_cmd[3].func=speaker_rc_id_set;
new->conf_cmd[4].string="set uplayer rc id";
new->conf_cmd[4].func=uplayer_rc_id_set;
new->conf_cmd[5].string="set downlayer rc id";
new->conf_cmd[5].func=downlayer_rc_id_set;
return new;
}
void
ospfh_init_continue(struct ospf *top)
{
ospf_sock_init();
top->fd = ospf_sock(top->ip_address);
top->t_read = thread_add_read (top->master, ospf_read, top, top->fd);
}
struct ospf_neighbor *
ospf_nbr_new (struct ospf *top)
{
struct ospf_neighbor *nbr;
/* Allcate new neighbor. */
nbr = (struct ospf_neighbor* )malloc(sizeof (struct ospf_neighbor));
nbr->top=top;
/* Set inheritance values. */
nbr->v_ls_upd = top->retransmit_interval;
nbr->t_ls_upd=NULL;
//list_init
nbr->ls_rxmt = list_new();
//见listlink.c
return nbr;
}
/*read the config file and execute the command*/
int
ospf_read_file (FILE *fp , struct ospf * top)
{
int ret;
struct vector * vline;
char * buf;
buf=(char*)XMALLOC(1,VTY_BUFSIZ);
memset(buf, 0 , VTY_BUFSIZ);
while (fgets (buf, VTY_BUFSIZ, fp))
{
vline = cmd_make_strvec (buf);
/* In case of comment line */
if (vline == NULL)
continue;
/* Execute configuration command : this is strict match */
ret = cmd_execute_command_strict (vline, NULL , top);
cmd_free_strvec (vline);
memset(buf, 0 , VTY_BUFSIZ);
}//end while
XFREE(1,buf);
return 0;
}
void
ospf_read_config (char *config_file, struct ospf * top)
{
char *cwd;
FILE *confp = NULL;
char *fullpath;
int ret;
char * temp="\\";
/* If -f flag specified. */
if (config_file != NULL)
{
if (! IS_DIRECTORY_SEP (config_file[0]))
{
cwd = _getcwd (NULL, _MAX_PATH );
fullpath = XMALLOC (1,
strlen (cwd) + strlen (config_file) + 2);
sprintf (fullpath, "%s%s%s", cwd, temp,config_file);
}
else
fullpath = config_file;
confp = fopen (fullpath, "r");
if (confp == NULL)
{
printf ("can't open configuration file [%s]\n",
config_file);
exit(1);
}
}
else
{
printf("no configuration file is given\n");
exit(1);
}
ret=ospf_read_file (confp,top);
fclose (confp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -