Commit f2835098 authored by Alessandro Rubini's avatar Alessandro Rubini

general: renamed a field, turned two macros to static inline

This commit has no technical effect: what works still works, and what
doesn't work still doesn't work.  Still, the inlines will do
type-checking at a later time when we have a structure for the ptp
header.

Moreover the renames allow me to trace all uses in order to change
them; it also generates build errors in wrpc-sw, forcing me to fix the new
use in there as well, when I update ppsi as submodule.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 50462520
......@@ -18,8 +18,12 @@ void posix_main_loop(struct pp_instance *ppi)
{
int delay_ms;
/*
* If we are sending or receiving raw ethernet frames,
* the ptp payload is one-eth-header bytes into the frame
*/
if (OPTS(ppi)->ethernet_mode)
NP(ppi)->proto_ofst = 14;
NP(ppi)->ptp_offset = ETH_HLEN;
/*
* The main loop here is based on select. While we are not
......
......@@ -101,10 +101,10 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
if (OPTS(ppi)->ethernet_mode) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
hdr = PROTO_HDR(pkt);
hdr = pp_get_header(ppi, pkt);
ret = posix_recv_msg(ppi, fd, hdr,
len + NP(ppi)->proto_ofst, t);
return ret <= 0 ? ret : ret - NP(ppi)->proto_ofst;
len + NP(ppi)->ptp_offset, t);
return ret <= 0 ? ret : ret - NP(ppi)->ptp_offset;
/* FIXME: check header */
}
......@@ -135,7 +135,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
struct ethhdr *hdr;
if (OPTS(ppi)->ethernet_mode) {
hdr = PROTO_HDR(pkt);
hdr = pp_get_header(ppi, pkt);
hdr->h_proto = htons(ETH_P_1588);
......@@ -143,7 +143,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
/* raw socket implementation always uses gen socket */
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, ETH_ALEN);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr,
len + NP(ppi)->proto_ofst, 0);
len + NP(ppi)->ptp_offset, 0);
}
/* else: UDP */
......@@ -349,11 +349,11 @@ int posix_net_init(struct pp_instance *ppi)
{
int i;
ppi->buf_out = calloc(1, PP_PACKET_SIZE + NP(ppi)->proto_ofst);
ppi->buf_out = calloc(1, PP_PACKET_SIZE + NP(ppi)->ptp_offset);
if (!ppi->buf_out)
return -1;
ppi->buf_out = PROTO_PAYLOAD(ppi->buf_out);
ppi->buf_out = pp_get_payload(ppi, ppi->buf_out);
if (OPTS(ppi)->ethernet_mode) {
PP_PRINTF("posix_net_init IEEE 802.3\n");
......
......@@ -106,7 +106,7 @@ static int wrpc_net_send(struct pp_instance *ppi, void *pkt, int len,
static int wrpc_net_init(struct pp_instance *ppi)
{
ppi->buf_out = buffer_out;
ppi->buf_out = PROTO_PAYLOAD(ppi->buf_out);
ppi->buf_out = pp_get_payload(ppi, ppi->buf_out);
ppi->buf_out += 4 - (((int)ppi->buf_out) % 4); /* FIXME Alignment */
wrpc_open_ch(ppi);
......
......@@ -130,11 +130,9 @@ struct pp_net_path {
/* FIXME check if useful Integer32 ucast_addr;*/
Integer32 mcast_addr;
Integer32 peer_mcast_addr;
int proto_ofst;
int ptp_offset;
int inited;
};
#define PROTO_HDR(x) ( (x) - NP(ppi)->proto_ofst);
#define PROTO_PAYLOAD(x) ( (x) + NP(ppi)->proto_ofst);
/*
* Structure for the individual ppsi link
......@@ -196,6 +194,7 @@ extern unsigned long pp_global_flags; /* Supplement ppi-specific ones */
#define PP_FLAG_NOTIMELOG 1 /* This is for a special case, I'm sorry */
/* We use data sets a lot, so have these helpers */
static inline struct pp_runtime_opts *OPTS(struct pp_instance *ppi)
{
......@@ -238,6 +237,18 @@ static inline struct pp_servo *SRV(struct pp_instance *ppi)
}
/* Sometimes (e.g., raw ethernet frames), we need to consider an offset */
static inline void *pp_get_header(struct pp_instance *ppi, void *ptp_payload)
{
return ptp_payload - NP(ppi)->ptp_offset;
}
static inline void *pp_get_payload(struct pp_instance *ppi, void *frame_ptr)
{
return frame_ptr + NP(ppi)->ptp_offset;
}
/*
* Each extension should fill this structure that is used to augment
* the standard states and avoid code duplications. Please remember
......
......@@ -7,7 +7,7 @@
#include <ppsi/diag.h>
#include "bare-linux.h"
/* 14 is ppi->proto_ofst for ethernet mode */
/* 14 is ptp_offset for ethernet mode */
Octet buffer_out[PP_PACKET_SIZE + 14];
/* FIXME: which socket we receive and send with? */
......@@ -18,14 +18,14 @@ static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(t);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd,
pkt - NP(ppi)->proto_ofst, len, 0);
pkt - NP(ppi)->ptp_offset, len, 0);
}
static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
{
struct bare_ethhdr *hdr;
hdr = PROTO_HDR(pkt);
hdr = pp_get_header(ppi, pkt);
hdr->h_proto = htons(ETH_P_1588);
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, 6);
......@@ -37,7 +37,7 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(t);
return sys_send(NP(ppi)->ch[chtype].fd, hdr,
len + NP(ppi)->proto_ofst, 0);
len + NP(ppi)->ptp_offset, 0);
}
#define SHUT_RD 0
......@@ -126,7 +126,7 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
static int bare_net_init(struct pp_instance *ppi)
{
ppi->buf_out = buffer_out;
ppi->buf_out = PROTO_PAYLOAD(ppi->buf_out);
ppi->buf_out = pp_get_payload(ppi, ppi->buf_out);
if (OPTS(ppi)->ethernet_mode) {
PP_PRINTF("bare_net_init IEEE 802.3\n");
......
......@@ -21,7 +21,7 @@ void bare_main_loop(struct pp_instance *ppi)
{
int delay_ms;
NP(ppi)->proto_ofst = 14;
NP(ppi)->ptp_offset = 14;
/*
* The main loop here is based on select. While we are not
......
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