Commit 0dd8be02 authored by Alessandro Rubini's avatar Alessandro Rubini

pp_net_path: remove inited field, ->init knows

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent a991e7e2
......@@ -337,13 +337,20 @@ static int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
return 0;
}
static int posix_net_exit(struct pp_instance *ppi);
/*
* Inits all the network stuff
*/
/* This function must be able to be called twice, and clean-up internally */
int posix_net_init(struct pp_instance *ppi)
{
int i;
if (NP(ppi)->ch[0].fd)
posix_net_exit(ppi);
/* The buffer is inside ppi, but we need to set pointers and align */
pp_prepare_pointers(ppi);
......
......@@ -100,8 +100,17 @@ static int wrpc_net_send(struct pp_instance *ppi, void *pkt, int len,
return snt;
}
static int wrpc_net_exit(struct pp_instance *ppi)
{
ptpd_netif_close_socket(NP(ppi)->ch[PP_NP_EVT].custom);
return 0;
}
/* This function must be able to be called twice, and clean-up internally */
static int wrpc_net_init(struct pp_instance *ppi)
{
if (NP(ppi)->ch[PP_NP_EVT].custom)
wrpc_net_exit(ppi);
pp_prepare_pointers(ppi);
wrpc_open_ch(ppi);
......@@ -109,12 +118,6 @@ static int wrpc_net_init(struct pp_instance *ppi)
}
static int wrpc_net_exit(struct pp_instance *ppi)
{
ptpd_netif_close_socket(NP(ppi)->ch[PP_NP_EVT].custom);
return 0;
}
struct pp_network_operations wrpc_net_ops = {
.init = wrpc_net_init,
.exit = wrpc_net_exit,
......
......@@ -132,7 +132,6 @@ struct pp_net_path {
Integer32 mcast_addr; /* FIXME: only ipv4/udp */
int ptp_offset;
int inited;
};
/*
......
......@@ -118,8 +118,18 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
return -1;
}
static int bare_net_exit(struct pp_instance *ppi)
{
return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR);
}
/* This function must be able to be called twice, and clean-up internally */
static int bare_net_init(struct pp_instance *ppi)
{
/* Here, socket may not be 0 (do we have stdin even if bare) */
if (NP(ppi)->ch[PP_NP_GEN].fd)
bare_net_exit(ppi);
/* The buffer is inside ppi, but we need to set pointers and align */
pp_prepare_pointers(ppi);
......@@ -135,10 +145,6 @@ static int bare_net_init(struct pp_instance *ppi)
return -1;
}
static int bare_net_exit(struct pp_instance *ppi)
{
return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR);
}
struct pp_network_operations bare_net_ops = {
.init = bare_net_init,
......
......@@ -18,14 +18,9 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
struct pp_runtime_opts *opt = OPTS(ppi);
int ret = 0;
if (NP(ppi)->inited)
ppi->n_ops->exit(ppi);
if (ppi->n_ops->init(ppi) < 0)
if (ppi->n_ops->init(ppi) < 0) /* it must handle being called twice */
goto failure;
NP(ppi)->inited = 1;
port->portState = PPS_INITIALIZING;
/*
......
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