diff --git a/arch-unix/unix-startup.c b/arch-unix/unix-startup.c index 14b547a8701ac2aab6adb74eac1c5cd5cc9a06a2..b7f60f5ec45529baf034103922ea868a819dc8c7 100644 --- a/arch-unix/unix-startup.c +++ b/arch-unix/unix-startup.c @@ -38,7 +38,6 @@ int main(int argc, char **argv) exit(__LINE__); ppg->max_links = PP_MAX_LINKS; - ppg->links = calloc(ppg->max_links, sizeof(struct pp_link)); ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS)); ppg->currentDS = calloc(1, sizeof(*ppg->currentDS)); ppg->parentDS = calloc(1, sizeof(*ppg->parentDS)); @@ -58,20 +57,18 @@ int main(int argc, char **argv) for (i = 0; i < ppg->nlinks; i++) { - struct pp_link *lnk = &ppg->links[i]; - ppi = &ppg->pp_instances[i]; NP(ppi)->ch[PP_NP_EVT].fd = -1; NP(ppi)->ch[PP_NP_GEN].fd = -1; ppi->glbs = ppg; - ppi->iface_name = lnk->iface_name; - ppi->ethernet_mode = (lnk->proto == 0) ? 1 : 0; - if (lnk->role == 1) { + ppi->iface_name = ppi->cfg.iface_name; + ppi->ethernet_mode = (ppi->cfg.proto == 0) ? 1 : 0; + if (ppi->cfg.role == 1) { ppi->master_only = 1; ppi->slave_only = 0; } - else if (lnk->role == 2) { + else if (ppi->cfg.role == 2) { ppi->master_only = 0; ppi->slave_only = 1; } diff --git a/arch-wrs/wrs-startup.c b/arch-wrs/wrs-startup.c index b482053facf922359793f76d936b39993753f1db..b5171ecd34e22facb14c67db8e2931fec78b17c5 100644 --- a/arch-wrs/wrs-startup.c +++ b/arch-wrs/wrs-startup.c @@ -58,7 +58,6 @@ int main(int argc, char **argv) exit(__LINE__); ppg->max_links = PP_MAX_LINKS; - ppg->links = calloc(ppg->max_links, sizeof(struct pp_link)); ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS)); ppg->currentDS = calloc(1, sizeof(*ppg->currentDS)); ppg->parentDS = calloc(1, sizeof(*ppg->parentDS)); @@ -78,20 +77,18 @@ int main(int argc, char **argv) for (i = 0; i < ppg->nlinks; i++) { - struct pp_link *lnk = &ppg->links[i]; - ppi = &ppg->pp_instances[i]; NP(ppi)->ch[PP_NP_EVT].fd = -1; NP(ppi)->ch[PP_NP_GEN].fd = -1; ppi->glbs = ppg; - ppi->iface_name = lnk->iface_name; - ppi->ethernet_mode = (lnk->proto == 0) ? 1 : 0; - if (lnk->role == 1) { + ppi->iface_name = ppi->cfg.iface_name; + ppi->ethernet_mode = (ppi->cfg.proto == 0) ? 1 : 0; + if (ppi->cfg.role == 1) { ppi->master_only = 1; ppi->slave_only = 0; } - else if (lnk->role == 2) { + else if (ppi->cfg.role == 2) { ppi->master_only = 0; ppi->slave_only = 1; } diff --git a/include/ppsi/pp-instance.h b/include/ppsi/pp-instance.h index 3743e5cb23b89df5bf43bba0d6df073f587ca28f..15a6acee2324cbe721589b734785e8ef577a55a3 100644 --- a/include/ppsi/pp-instance.h +++ b/include/ppsi/pp-instance.h @@ -108,6 +108,18 @@ struct pp_net_path { int ptp_offset; }; +/* + * Struct containg the result of ppsi.conf parsing: one for each link + * (see lib/conf.c) + */ +struct pp_instance_cfg { + char link_name[16]; + char iface_name[16]; + int proto; /* 0: raw, 1: udp */ + int role; /* 0: auto, 1: master, 2: slave */ + int ext; /* 0: none, 1: whiterabbit */ /* FIXME extension enumeration */ +}; + /* * Structure for the individual ppsi link */ @@ -167,20 +179,11 @@ struct pp_instance { ethernet_mode:1; char *iface_name; int port_idx; -}; -/* - * Struct containg the result of ppsi.conf parsing: one for each link - * (see lib/conf.c) - */ -struct pp_link { - char link_name[16]; - char iface_name[16]; - int proto; /* 0: raw, 1: udp */ - int role; /* 0: auto, 1: master, 2: slave */ - int ext; /* 0: none, 1: whiterabbit */ /* FIXME extension enumeration */ + struct pp_instance_cfg cfg; }; + /* * Structure for the multi-port ppsi instance. */ @@ -204,7 +207,6 @@ struct pp_globals { int nlinks; int max_links; - struct pp_link *links; void *arch_data; /* if arch needs it */ /* FIXME Here include all is common to many interfaces */ diff --git a/lib/conf.c b/lib/conf.c index ff0a61b1fe502be09258252978c8ffdda95b90cd..db692fce97ef996b2a1152cb520fd4031927dcc0 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -68,13 +68,15 @@ static int handle_link(struct pp_globals *ppg, char *val) pp_printf("ppsi: Too many links in config file\n"); exit(1); } - strcpy(ppg->links[ppg->nlinks].link_name, val); /* FIXME check val len */ + /* FIXME: strncpy (it is missing in bare archs by now) */ + strcpy(ppg->pp_instances[ppg->nlinks].cfg.link_name, val); return 1; } static int handle_iface(struct pp_globals *ppg, char *val) { - strcpy(ppg->links[ppg->nlinks].iface_name, val); /* FIXME check iface len */ + /* FIXME: strncpy (it is missing in bare archs by now) */ + strcpy(ppg->pp_instances[ppg->nlinks].iface_name, val); return 1; } @@ -98,7 +100,8 @@ static int handle_proto(struct pp_globals *ppg, char *val) switch(v_id) { case KW_RAW: case KW_UDP: - ppg->links[ppg->nlinks].proto = v_id - KW_RAW; + ppg->pp_instances[ppg->nlinks].cfg.proto + = v_id - KW_RAW; break; default: return 0; @@ -115,7 +118,8 @@ static int handle_role(struct pp_globals *ppg, char *val) case KW_AUTO: case KW_MASTER: case KW_SLAVE: - ppg->links[ppg->nlinks].role = v_id - KW_AUTO; + ppg->pp_instances[ppg->nlinks].cfg.role + = v_id - KW_AUTO; break; default: return 0; @@ -131,7 +135,8 @@ static int handle_ext(struct pp_globals *ppg, char *val) switch(v_id) { case KW_NONE: case KW_WHITERAB: - ppg->links[ppg->nlinks].ext = v_id - KW_NONE; + ppg->pp_instances[ppg->nlinks].cfg.ext + = v_id - KW_NONE; break; default: return 0; @@ -174,7 +179,6 @@ static int pp_parse_conf(struct pp_globals *ppg, char *conf, int len) /* ppg->nlinks is initialized to -1 and increased at first link found, * so that we can use it as array index */ ppg->nlinks = -1; - memset(ppg->links, 0, ppg->max_links * sizeof(struct pp_link)); for (i = 0; i < len; i++) { c = conf[i]; diff --git a/proto-ext-whiterabbit/hooks.c b/proto-ext-whiterabbit/hooks.c index 6e595b8492804b673ede064381221e49a8449c67..48bfb756caea9ef93d96a099144592d7e35a756b 100644 --- a/proto-ext-whiterabbit/hooks.c +++ b/proto-ext-whiterabbit/hooks.c @@ -31,15 +31,14 @@ static int wr_open(struct pp_globals *ppg, struct pp_runtime_opts *rt_opts) } for (i = 0; i < ppg->nlinks; i++) { - struct pp_link *lnk = &ppg->links[i]; struct pp_instance *ppi = &ppg->pp_instances[i]; /* FIXME check if correct: assign to each instance the same * wr_data. May I move it to pp_globals? */ ppg->pp_instances[i].ext_data = &wr_data; - if (lnk->ext) { - switch (lnk->role) { + if (ppi->cfg.ext) { + switch (ppi->cfg.role) { case 1: WR_DSPOR(ppi)->wrConfig = WR_M_ONLY; break;