Commit e6273caf authored by Aurelio Colosimo's avatar Aurelio Colosimo

ieee 802.3 transport implemented

We now use raw sockets as default. The choice, for gnu-linux arch,
can be done by defining PP_NET_UDP or PP_NET_IEEE_802_3.
New constant PP_ETHERTYPE=0x88f7 is defined in ieee1588_types.h,
as defined in IEEE specification.
parent 69808152
......@@ -37,7 +37,7 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
struct bare_sockaddr_ll addr;
/* open socket */
sock = sys_socket(PF_PACKET, SOCK_RAW, PP_PROTO_NR);
sock = sys_socket(PF_PACKET, SOCK_RAW, PP_ETHERTYPE);
if (sock < 0) {
pp_diag_error(ppi, bare_errno);
pp_diag_fatal(ppi, "socket()", "");
......@@ -64,7 +64,7 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
/* bind and setsockopt */
memset(&addr, 0, sizeof(addr));
addr.sll_family = PF_PACKET;
addr.sll_protocol = htons(PP_PROTO_NR);
addr.sll_protocol = htons(PP_ETHERTYPE);
addr.sll_ifindex = iindex;
if (sys_bind(sock, (struct bare_sockaddr *)&addr, sizeof(addr)) < 0) {
pp_diag_error(ppi, bare_errno);
......
......@@ -75,9 +75,8 @@ void bare_main_loop(struct pp_instance *ppi)
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
/* FIXME: PP_PROTO_NR is a legacy number */
if (((struct bare_ethhdr *)packet)->h_proto
!= htons(PP_PROTO_NR))
!= htons(PP_ETHERTYPE))
goto again;
delay_ms = pp_state_machine(ppi, packet, i);
......
......@@ -58,8 +58,8 @@ void posix_main_loop(struct pp_instance *ppi)
goto again;
}
/* Warning: PP_PROTO_NR is endian-agnostic by design */
if (((struct ethhdr *)packet)->h_proto != htons(PP_PROTO_NR)) {
/* Warning: PP_ETHERTYPE is endian-agnostic by design */
if (((struct ethhdr *)packet)->h_proto != htons(PP_ETHERTYPE)) {
delay_ms = -1;
goto again;
}
......
......@@ -20,9 +20,9 @@
#include <pptp/diag.h>
#include "posix.h"
/* Uncomment one of the following */
#define PP_NET_UDP
/* #define PP_NET_IEEE_802_3 */
/* Uncomment one (and only one!) of the following */
/* #define PP_NET_UDP */
#define PP_NET_IEEE_802_3
/* Receive and send is *not* so trivial */
......@@ -53,7 +53,8 @@ int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len,
#endif /* PP_NET_UDP */
#ifdef PP_NET_IEEE_802_3
/* TODO raw sockets */
/* raw sockets implementation always use gen socket */
return recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
#endif /* PP_NET_IEEE_802_3 */
return -1;
......@@ -78,7 +79,8 @@ int posix_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype,
#endif /* PP_NET_UDP */
#ifdef PP_NET_IEEE_802_3
/* TODO raw sockets */
/* raw sockets implementation always use gen socket */
return send(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
#endif /* PP_NET_IEEE_802_3 */
return -1;
......@@ -238,13 +240,12 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
#ifdef PP_NET_IEEE_802_3
/* TODO: raw socket check open channel */
int sock, iindex;
struct ifreq ifr;
struct sockaddr_ll addr;
/* open socket */
sock = socket(PF_PACKET, SOCK_RAW, PP_PROTO_NR);
sock = socket(PF_PACKET, SOCK_RAW, PP_ETHERTYPE);
if (sock < 0) {
pp_diag_error_str2(ppi, "socket()", strerror(errno));
return -1;
......@@ -271,7 +272,7 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
/* bind and setsockopt */
memset(&addr, 0, sizeof(addr));
addr.sll_family = AF_PACKET;
addr.sll_protocol = htons(PP_PROTO_NR);
addr.sll_protocol = htons(PP_ETHERTYPE);
addr.sll_ifindex = iindex;
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
pp_diag_error_str2(ppi, "bind", strerror(errno));
......@@ -291,8 +292,8 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
*/
int posix_net_init(struct pp_instance *ppi)
{
int i;
#ifdef PP_NET_UDP
int i;
PP_PRINTF("posix_net_init UDP\n");
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
if (posix_open_ch(ppi, OPTS(ppi)->iface_name, i))
......@@ -303,7 +304,11 @@ int posix_net_init(struct pp_instance *ppi)
#ifdef PP_NET_IEEE_802_3
PP_PRINTF("posix_net_init IEEE 802.3\n");
/* TODO raw sockets */
/* raw sockets implementation always use gen socket */
if (posix_open_ch(ppi, OPTS(ppi)->iface_name, PP_NP_GEN))
return -1;
return 0;
#endif /* PP_NET_IEEE_802_3 */
PP_PRINTF("Error: pptp Compiled with unsupported network protocol!!\n");
......@@ -356,7 +361,7 @@ int posix_net_shutdown(struct pp_instance *ppi)
#endif /* PP_NET_UDP */
#ifdef PP_NET_IEEE_802_3
/* TODO raw sockets */
close(NP(ppi)->ch[PP_NP_GEN].fd);
#endif /* PP_NET_IEEE_802_3 */
return -1;
......@@ -364,7 +369,7 @@ int posix_net_shutdown(struct pp_instance *ppi)
int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
{
#ifdef PP_NET_UDP
fd_set set;
int i;
int ret = 0;
......@@ -381,6 +386,7 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
NP(ppi)->ch[PP_NP_GEN].pkt_present = 0;
NP(ppi)->ch[PP_NP_EVT].pkt_present = 0;
#ifdef PP_NET_UDP
maxfd = (NP(ppi)->ch[PP_NP_GEN].fd > NP(ppi)->ch[PP_NP_EVT].fd) ?
NP(ppi)->ch[PP_NP_GEN].fd : NP(ppi)->ch[PP_NP_EVT].fd;
FD_ZERO(&set);
......@@ -414,7 +420,31 @@ _end:
#endif /* PP_NET_UDP */
#ifdef PP_NET_IEEE_802_3
/* TODO raw sockets */
maxfd = NP(ppi)->ch[PP_NP_GEN].fd;
FD_ZERO(&set);
FD_SET(NP(ppi)->ch[PP_NP_GEN].fd, &set);
i = select(maxfd + 1, &set, NULL, NULL, &arch_data->tv);
if (i < 0 && errno != EINTR)
exit(__LINE__);
if (i < 0) {
ret = i;
goto _end;
}
if (i == 0)
goto _end;
if (FD_ISSET(NP(ppi)->ch[PP_NP_GEN].fd, &set)) {
ret++;
NP(ppi)->ch[PP_NP_GEN].pkt_present = 1;
}
_end:
return ret;
#endif /* PP_NET_IEEE_802_3 */
return -1;
......
......@@ -43,9 +43,9 @@ void spec_main_loop(struct pp_instance *ppi)
pp_printf(" %02x", packet[j]);
pp_printf("\n");
}
/* Warning: PP_PROTO_NR is endian-agnostic by design */
/* Warning: PP_ETHERTYPE is endian-agnostic by design */
if (((struct spec_ethhdr *)packet)->h_proto !=
htons(PP_PROTO_NR))
htons(PP_ETHERTYPE))
continue;
delay_ms = pp_state_machine(ppi, packet, i);
}
......
......@@ -9,6 +9,9 @@
#include <stdint.h>
/* See F.2, pag.223 */
#define PP_ETHERTYPE 0x88f7
typedef enum {FALSE=0, TRUE} Boolean;
typedef uint8_t Octet;
typedef int8_t Integer8;
......
......@@ -143,7 +143,7 @@ struct pp_servo {
#define PP_NP_GEN 0
#define PP_NP_EVT 1
#define PP_NP_LAST 1
#define PP_NP_LAST 2
struct pp_net_path {
struct pp_channel ch[2]; /* event and general channel (see above
* #define's */
......@@ -365,9 +365,4 @@ extern pp_action pp_initializing, pp_faulty, pp_disabled, pp_listening,
/* The engine */
extern int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen);
/*
* FIXME Whe talk raw sockets on PP_PROTO_NR.
*/
#define PP_PROTO_NR 0xcccc
#endif /* __PTP_PROTO_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