Commit 237af5c4 authored by Alessandro Rubini's avatar Alessandro Rubini

time-unix: use two init functions instead of switch(proto)

This is partly undoing the previous commit, but there is really
no common code between udp and raw in the init path.

Besides, initializing for vlan means creating a raw socket, and
we'd break the whole "switch" idea.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 81590d98
......@@ -193,22 +193,16 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
}
/* To open a channel we must bind to an interface and so on */
static int unix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
static int unix_open_ch_raw(struct pp_instance *ppi, char *ifname, int chtype)
{
int sock = -1;
int temp, iindex;
struct in_addr iface_addr, net_addr;
struct ifreq ifr;
struct sockaddr_in addr;
struct sockaddr_ll addr_ll;
struct ip_mreq imr;
struct packet_mreq pmr;
char addr_str[INET_ADDRSTRLEN];
char *context;
switch(ppi->proto) {
case PPSI_PROTO_RAW:
/* open socket */
context = "socket()";
sock = socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
......@@ -256,7 +250,25 @@ static int unix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
return 0;
case PPSI_PROTO_UDP:
err_out:
pp_printf("%s: %s: %s\n", __func__, context, strerror(errno));
if (sock >= 0)
close(sock);
NP(ppi)->ch[chtype].fd = -1;
return -1;
}
static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
{
int sock = -1;
int temp;
struct in_addr iface_addr, net_addr;
struct ifreq ifr;
struct sockaddr_in addr;
struct ip_mreq imr;
char addr_str[INET_ADDRSTRLEN];
char *context;
context = "socket()";
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
......@@ -350,12 +362,6 @@ static int unix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
NP(ppi)->ch[chtype].fd = sock;
return 0;
case PPSI_PROTO_VLAN:
/* FIXME */
default:
return -1;
}
err_out:
pp_printf("%s: %s: %s\n", __func__, context, strerror(errno));
if (sock >= 0)
......@@ -383,15 +389,20 @@ static int unix_net_init(struct pp_instance *ppi)
switch(ppi->proto) {
case PPSI_PROTO_RAW:
pp_diag(ppi, frames, 1, "unix_net_init IEEE 802.3\n");
pp_diag(ppi, frames, 1, "unix_net_init raw Ethernet\n");
/* raw sockets implementation always use gen socket */
return unix_open_ch(ppi, ppi->iface_name, PP_NP_GEN);
return unix_open_ch_raw(ppi, ppi->iface_name, PP_NP_GEN);
case PPSI_PROTO_UDP:
if (ppi->nvlans) {
/* If "proto udp" is set after setting vlans... */
pp_printf("Error: can't use UDP with VLAN support\n");
exit(1);
}
pp_diag(ppi, frames, 1, "unix_net_init UDP\n");
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
if (unix_open_ch(ppi, ppi->iface_name, i))
if (unix_open_ch_udp(ppi, ppi->iface_name, i))
return -1;
}
return 0;
......
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