Commit 691947bb authored by Aurelio Colosimo's avatar Aurelio Colosimo

First declaration and minimal usage of struct struct pp_globals

This patch introduces struct pp_globals in include/ppsi/pp-instance.h
and starts using it in arch-gnu-linux. Actually, the behaviour does not
change yet, and only one interface is taken into account. In main-loop.c
there is a proposal for interfaces enumeration, based on runtime env
variables:
- one PPROTO_IF_NUM (number of interfaces);
- many PPROTO_IF_XX (each one defining an interface name).
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 0c74aa23
......@@ -13,9 +13,12 @@
#include <ppsi/ppsi.h>
#include "posix.h"
void posix_main_loop(struct pp_instance *ppi)
void posix_main_loop(struct pp_globals *ppg)
{
int delay_ms;
struct pp_instance *ppi;
ppi = &ppg->pp_instances[0];
/*
* If we are sending or receiving raw ethernet frames,
......
......@@ -18,23 +18,45 @@ CONST_VERBOSITY int pp_diag_verbosity = 0;
int main(int argc, char **argv)
{
struct pp_globals *ppg;
struct pp_instance *ppi;
char *ifname;
char *ifname, *nports;
char tmp[16];
int i = 0;
setbuf(stdout, NULL);
/*
* Here, we may fork or whatever for each interface.
* To keep things simple, just run one thing for one interface.
*/
ifname = getenv("PPROTO_IF");
if (!ifname)
ifname = "eth0";
/* We are hosted, so we can allocate */
ppi = calloc(1, sizeof(*ppi));
if (!ppi)
ppg = calloc(1, sizeof(*ppg));
if (!ppg)
exit(__LINE__);
nports = getenv("PPROTO_IF_NUM");
if (nports)
ppg->nports = atoi(nports);
else
ppg->nports = 1;
ppg->pp_instances = calloc(ppg->nports, sizeof(struct pp_instance));
if (!ppg->pp_instances)
exit(__LINE__);
for (; i < ppg->nports; i++) {
sprintf(tmp, "PPROTO_IF_%02d", i);
ifname = getenv(tmp);
if (!ifname) {
sprintf(tmp, "eth%d", i);
ifname = tmp;
}
ppi = &ppg->pp_instances[i];
/* FIXME check all of these calloc's, since some stuff will be
* part of pp_globals */
ppi->defaultDS = calloc(1, sizeof(*ppi->defaultDS));
ppi->currentDS = calloc(1, sizeof(*ppi->currentDS));
ppi->parentDS = calloc(1, sizeof(*ppi->parentDS));
......@@ -54,11 +76,16 @@ int main(int argc, char **argv)
pp_open_instance(ppi, NULL);
OPTS(ppi)->iface_name = ifname;
/* FIXME temporary workaround to make the first interface work as in the past */
if (i == 0)
OPTS(ppi)->iface_name = strdup(ifname);
}
if (pp_parse_cmdline(ppi, argc, argv) != 0)
/* FIXME temporary workaround: pp_parse_cmdline will receive ppg */
if (pp_parse_cmdline(&ppg->pp_instances[0], argc, argv) != 0)
return -1;
posix_main_loop(ppi);
posix_main_loop(ppg);
return 0; /* never reached */
}
......@@ -14,7 +14,7 @@ struct posix_arch_data {
extern int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms);
extern void posix_main_loop(struct pp_instance *ppi);
extern void posix_main_loop(struct pp_globals *ppg);
extern struct pp_network_operations posix_net_ops;
extern struct pp_time_operations posix_time_ops;
......@@ -183,4 +183,13 @@ struct pp_instance {
waiting_for_follow:1;
};
/*
* Structure for the multi-port ppsi instance.
*/
struct pp_globals {
int nports;
struct pp_instance *pp_instances;
/* FIXME Here include all is common to many interfaces */
};
#endif /* __PPSI_PP_INSTANCE_H__ */
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