Commit faa87f7a authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

remove arguments to net->send; some fixes as side effect

Most arguments of net->send are redundant, as the ppi includes all
info. In particular, chtype and "is_pdelay_addr" derive from the
message type.  And the timestamp is always internal.

I chose not to remove message, len and msgtype because the message
being sent includes the header (ppi->tx_offset), so there's some
calculation to extract them.  This may happen in a later commit, if I
find that is a size improvement.

Bugs fixed as a side effect:
   - the "if" for "is_pelay" missed PDELAY_RESP_F_UP (now it's in msgtype.c)
   - wrpc pdelay was always using the e2e mac address

This commit decreases the size of all archs by 60 bytes, but increases
wrpc by 20 bytes because of the fix above
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 8f25cb18
......@@ -172,9 +172,7 @@ struct pp_network_operations {
int (*exit)(struct pp_instance *ppi);
int (*recv)(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t);
/* chtype here is PP_NP_GEN or PP_NP_EVT -- use_pdelay must be 0 */
int (*send)(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr);
int (*send)(struct pp_instance *ppi, void *pkt, int len, int msgtype);
int (*check_packet)(struct pp_globals *ppg, int delay_ms);
};
......
......@@ -395,14 +395,8 @@ int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
int pdelay_addr = 0;
if (msgtype == PPM_PDELAY_REQ || msgtype == PPM_PDELAY_RESP)
pdelay_addr = 1;
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + ppi->tx_offset,
&ppi->last_snt_time, chtype,
pdelay_addr) < msglen) {
msgtype) < msglen) {
pp_diag(ppi, frames, 1, "%s(%d) Message can't be sent\n",
pp_msgtype_info[msgtype].name, msgtype);
return PP_SEND_ERROR;
......
......@@ -25,17 +25,20 @@ static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
}
static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
int msgtype)
{
struct bare_ethhdr *hdr = pkt;
TimeInternal *t = &ppi->last_snt_time;
static const uint8_t macaddr[2][ETH_ALEN] = {
[PP_E2E_MECH] = PP_MCAST_MACADDRESS,
[PP_P2P_MECH] = PP_PDELAY_MACADDRESS,
};
int is_pdelay = pp_msgtype_info[msgtype].is_pdelay;
int ret;
hdr->h_proto = htons(ETH_P_1588);
if (use_pdelay_addr)
memcpy(hdr->h_dest, PP_PDELAY_MACADDRESS, 6);
else
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, 6);
memcpy(hdr->h_dest, macaddr[is_pdelay], ETH_ALEN);
/* raw socket implementation always uses gen socket */
memcpy(hdr->h_source, ppi->ch[PP_NP_GEN].addr, 6);
......@@ -43,7 +46,7 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t)
ppi->t_ops->get(ppi, t);
ret = sys_send(ppi->ch[chtype].fd, pkt, len, 0);
ret = sys_send(ppi->ch[PP_NP_GEN].fd, pkt, len, 0);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
......
......@@ -162,8 +162,10 @@ static int sim_net_recv(struct pp_instance *ppi, void *pkt, int len,
}
static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
int msgtype)
{
int chtype = pp_msgtype_info[msgtype].chtype;
TimeInternal *t = &ppi->last_snt_time;
struct sim_ppi_arch_data *data = SIM_PPI_ARCH(ppi);
struct sockaddr_in addr;
struct sim_pending_pkt pending;
......
......@@ -177,16 +177,24 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
}
static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
int msgtype)
{
int chtype = pp_msgtype_info[msgtype].chtype;
struct sockaddr_in addr;
struct ethhdr *hdr = pkt;
struct pp_vlanhdr *vhdr = pkt;
struct pp_channel *ch = ppi->ch + chtype;
static uint16_t udpport[] = {
TimeInternal *t = &ppi->last_snt_time;
int is_pdelay = pp_msgtype_info[msgtype].is_pdelay;
static const uint16_t udpport[] = {
[PP_NP_GEN] = PP_GEN_PORT,
[PP_NP_EVT] = PP_EVT_PORT,
};
/* FIXME: udp address for sendto */
static const uint8_t macaddr[2][ETH_ALEN] = {
[PP_E2E_MECH] = PP_MCAST_MACADDRESS,
[PP_P2P_MECH] = PP_PDELAY_MACADDRESS,
};
int ret;
/* To fake a network frame loss, set the timestamp and do not send */
......@@ -203,10 +211,7 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
ch = ppi->ch + PP_NP_GEN;
hdr->h_proto = htons(ETH_P_1588);
if (use_pdelay_addr)
memcpy(hdr->h_dest, PP_PDELAY_MACADDRESS, ETH_ALEN);
else
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
memcpy(hdr->h_dest, macaddr[is_pdelay], ETH_ALEN);
memcpy(hdr->h_source, ch->addr, ETH_ALEN);
if (t)
......@@ -229,10 +234,7 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
vhdr->h_tci = htons(ppi->peer_vid); /* prio is 0 */
vhdr->h_tpid = htons(0x8100);
if (use_pdelay_addr)
memcpy(hdr->h_dest, PP_PDELAY_MACADDRESS, ETH_ALEN);
else
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
memcpy(hdr->h_dest, macaddr[is_pdelay], ETH_ALEN);
memcpy(vhdr->h_source, ch->addr, ETH_ALEN);
if (t)
......@@ -252,6 +254,8 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
addr.sin_port = htons(udpport[chtype]);
addr.sin_addr.s_addr = ppi->mcast_addr;
/* FIXME: differentiate pldeay mac address */
if (t)
ppi->t_ops->get(ppi, t);
......
......@@ -81,16 +81,23 @@ static int wrpc_net_recv(struct pp_instance *ppi, void *pkt, int len,
}
static int wrpc_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
int msgtype)
{
int snt;
struct wrpc_socket *sock;
struct wr_timestamp wr_ts;
struct wr_sockaddr addr;
TimeInternal *t = &ppi->last_snt_time;
int is_pdelay = pp_msgtype_info[msgtype].is_pdelay;
static const uint8_t macaddr[2][ETH_ALEN] = {
[PP_E2E_MECH] = PP_MCAST_MACADDRESS,
[PP_P2P_MECH] = PP_PDELAY_MACADDRESS,
};
sock = ppi->ch[PP_NP_EVT].custom;
addr.ethertype = ETH_P_1588;
memcpy(&addr.mac, PP_MCAST_MACADDRESS, sizeof(mac_addr_t));
memcpy(&addr.mac, macaddr[is_pdelay], sizeof(mac_addr_t));
snt = ptpd_netif_sendto(sock, &addr, pkt, len, &wr_ts);
......
......@@ -448,16 +448,24 @@ static void poll_tx_timestamp(struct pp_instance *ppi, void *pkt, int len,
}
static int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
int msgtype)
{
int chtype = pp_msgtype_info[msgtype].chtype;
struct sockaddr_in addr;
struct ethhdr *hdr = pkt;
struct pp_vlanhdr *vhdr = pkt;
struct pp_channel *ch = ppi->ch + chtype;
TimeInternal *t = &ppi->last_snt_time;
int is_pdelay = pp_msgtype_info[msgtype].is_pdelay;
static uint16_t udpport[] = {
[PP_NP_GEN] = PP_GEN_PORT,
[PP_NP_EVT] = PP_EVT_PORT,
};
/* FIXME: udp address for sendto */
static const uint8_t macaddr[2][ETH_ALEN] = {
[PP_E2E_MECH] = PP_MCAST_MACADDRESS,
[PP_P2P_MECH] = PP_PDELAY_MACADDRESS,
};
struct wrs_socket *s;
int ret, fd, drop;
......@@ -478,10 +486,7 @@ static int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
if (drop)
hdr->h_proto++;
if (use_pdelay_addr)
memcpy(hdr->h_dest, PP_PDELAY_MACADDRESS, ETH_ALEN);
else
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
memcpy(hdr->h_dest, macaddr[is_pdelay], ETH_ALEN);
memcpy(hdr->h_source, ch->addr, ETH_ALEN);
if (t)
......@@ -514,11 +519,7 @@ static int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
if (drop)
hdr->h_proto++;
if (use_pdelay_addr)
memcpy(vhdr->h_dest, PP_PDELAY_MACADDRESS, ETH_ALEN);
else
memcpy(vhdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
memcpy(hdr->h_dest, macaddr[is_pdelay], ETH_ALEN);
memcpy(vhdr->h_source, ch->addr, ETH_ALEN);
if (t)
......
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