Commit 80ab8482 authored by Alessandro Rubini's avatar Alessandro Rubini

general: peer and peer_vid are ppi-wide, not channel-wide

With UDP we have two channels but we talk with the same peers.
Moreover, we reply with a general message to an event message, so
having two peers was plain wrong.

I'm well aware this commit should happen before vlans are introduced,
but I don't want to deal with all the conflicts in moving it back.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f350de47
...@@ -62,8 +62,6 @@ struct pp_channel { ...@@ -62,8 +62,6 @@ struct pp_channel {
}; };
void *arch_data; /* Other arch-private info, if any */ void *arch_data; /* Other arch-private info, if any */
unsigned char addr[6]; /* Our own MAC address */ unsigned char addr[6]; /* Our own MAC address */
unsigned char peer[6]; /* Our peer's MAC address */
uint16_t peer_vid; /* Our peer's VID (for PROTO_VLAN) */
int pkt_present; int pkt_present;
}; };
...@@ -151,6 +149,8 @@ struct pp_instance { ...@@ -151,6 +149,8 @@ struct pp_instance {
struct pp_channel ch[__NR_PP_NP]; /* general and event ch */ struct pp_channel ch[__NR_PP_NP]; /* general and event ch */
Integer32 mcast_addr; /* only ipv4/udp */ Integer32 mcast_addr; /* only ipv4/udp */
int tx_offset, rx_offset; /* ptp payload vs send/recv */ int tx_offset, rx_offset; /* ptp payload vs send/recv */
unsigned char peer[6]; /* Our peer's MAC address */
uint16_t peer_vid; /* Our peer's VID (for PROTO_VLAN) */
/* Times, for the various offset computations */ /* Times, for the various offset computations */
TimeInternal t1, t2, t3, t4; /* *the* stamps */ TimeInternal t1, t2, t3, t4; /* *the* stamps */
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <ppsi/lib.h> #include <ppsi/lib.h>
#include "wr-constants.h" #include "wr-constants.h"
#define WRS_PPSI_SHMEM_VERSION 10 /* added peer_vid */ #define WRS_PPSI_SHMEM_VERSION 11 /* peer is per-ppi, not per-chan */
/* /*
* This structure is used as extension-specific data in the DSPort * This structure is used as extension-specific data in the DSPort
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/* unix_recv_msg uses recvmsg for timestamp query */ /* unix_recv_msg uses recvmsg for timestamp query */
static int unix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, static int unix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
TimeInternal *t, uint16_t *peer_vid) TimeInternal *t)
{ {
struct ethhdr *hdr = pkt; struct ethhdr *hdr = pkt;
ssize_t ret; ssize_t ret;
...@@ -108,9 +108,9 @@ static int unix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, ...@@ -108,9 +108,9 @@ static int unix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
break; /* ok */ break; /* ok */
if (i == ppi->nvlans) if (i == ppi->nvlans)
return -2; /* not ours: say it's dropped */ return -2; /* not ours: say it's dropped */
*peer_vid = ppi->vlans[i]; ppi->peer_vid = ppi->vlans[i];
} else { } else {
*peer_vid = 0; ppi->peer_vid = 0;
} }
if (ppsi_drop_rx()) { if (ppsi_drop_rx()) {
...@@ -137,16 +137,16 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -137,16 +137,16 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
case PPSI_PROTO_VLAN: case PPSI_PROTO_VLAN:
ch2 = ppi->ch + PP_NP_GEN; ch2 = ppi->ch + PP_NP_GEN;
ret = unix_recv_msg(ppi, ch2->fd, pkt, len, t, &ch2->peer_vid); ret = unix_recv_msg(ppi, ch2->fd, pkt, len, t);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
if (hdr->h_proto != htons(ETH_P_1588)) if (hdr->h_proto != htons(ETH_P_1588))
return 0; return 0;
memcpy(ppi->ch[PP_NP_GEN].peer, hdr->h_source, ETH_ALEN); memcpy(ppi->peer, hdr->h_source, ETH_ALEN);
if (pp_diag_allow(ppi, frames, 2)) { if (pp_diag_allow(ppi, frames, 2)) {
if (ppi->proto == PPSI_PROTO_VLAN) if (ppi->proto == PPSI_PROTO_VLAN)
pp_printf("recv: VLAN %i\n", ch2->peer_vid); pp_printf("recv: VLAN %i\n", ppi->peer_vid);
dump_1588pkt("recv: ", pkt, ret, t); dump_1588pkt("recv: ", pkt, ret, t);
} }
return ret; return ret;
...@@ -159,9 +159,9 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -159,9 +159,9 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
ret = -1; ret = -1;
if (ch1->pkt_present) if (ch1->pkt_present)
ret = unix_recv_msg(ppi, ch1->fd, pkt, len, t, NULL); ret = unix_recv_msg(ppi, ch1->fd, pkt, len, t);
else if (ch2->pkt_present) else if (ch2->pkt_present)
ret = unix_recv_msg(ppi, ch2->fd, pkt, len, t, NULL); ret = unix_recv_msg(ppi, ch2->fd, pkt, len, t);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
/* We can't save the peer's mac address in UDP mode */ /* We can't save the peer's mac address in UDP mode */
...@@ -216,7 +216,7 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -216,7 +216,7 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
/* similar to sending raw frames, but w/ different header */ /* similar to sending raw frames, but w/ different header */
ch = ppi->ch + PP_NP_GEN; ch = ppi->ch + PP_NP_GEN;
vhdr->h_proto = htons(ETH_P_1588); vhdr->h_proto = htons(ETH_P_1588);
vhdr->h_tci = htons(ch->peer_vid); /* prio is 0 */ vhdr->h_tci = htons(ppi->peer_vid); /* prio is 0 */
vhdr->h_tpid = htons(0x8100); vhdr->h_tpid = htons(0x8100);
memcpy(vhdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN); memcpy(vhdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
......
...@@ -158,7 +158,7 @@ static void wrs_linearize_rx_timestamp(TimeInternal *ts, ...@@ -158,7 +158,7 @@ static void wrs_linearize_rx_timestamp(TimeInternal *ts,
static int wrs_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, static int wrs_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
TimeInternal *t, uint16_t *peer_vid) TimeInternal *t)
{ {
struct ethhdr *hdr = pkt; struct ethhdr *hdr = pkt;
struct wrs_socket *s; struct wrs_socket *s;
...@@ -250,9 +250,9 @@ drop: ...@@ -250,9 +250,9 @@ drop:
break; /* ok */ break; /* ok */
if (i == ppi->nvlans) if (i == ppi->nvlans)
return 0; /* not ours */ return 0; /* not ours */
*peer_vid = ppi->vlans[i]; ppi->peer_vid = ppi->vlans[i];
} else { } else {
*peer_vid = 0; ppi->peer_vid = 0;
} }
if (ppsi_drop_rx()) { if (ppsi_drop_rx()) {
...@@ -275,16 +275,16 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -275,16 +275,16 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
case PPSI_PROTO_VLAN: case PPSI_PROTO_VLAN:
ch2 = ppi->ch + PP_NP_GEN; ch2 = ppi->ch + PP_NP_GEN;
ret = wrs_recv_msg(ppi, ch2->fd, pkt, len, t, &ch2->peer_vid); ret = wrs_recv_msg(ppi, ch2->fd, pkt, len, t);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
if (hdr->h_proto != htons(ETH_P_1588)) if (hdr->h_proto != htons(ETH_P_1588))
return 0; return 0;
memcpy(ppi->ch[PP_NP_GEN].peer, hdr->h_source, ETH_ALEN); memcpy(ppi->peer, hdr->h_source, ETH_ALEN);
if (pp_diag_allow(ppi, frames, 2)) { if (pp_diag_allow(ppi, frames, 2)) {
if (ppi->proto == PPSI_PROTO_VLAN) if (ppi->proto == PPSI_PROTO_VLAN)
pp_printf("recv: VLAN %i\n", ch2->peer_vid); pp_printf("recv: VLAN %i\n", ppi->peer_vid);
dump_1588pkt("recv: ", pkt, ret, t); dump_1588pkt("recv: ", pkt, ret, t);
} }
break; break;
...@@ -295,9 +295,9 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -295,9 +295,9 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
ch2 = &(ppi->ch[PP_NP_GEN]); ch2 = &(ppi->ch[PP_NP_GEN]);
if (ch1->pkt_present) if (ch1->pkt_present)
ret = wrs_recv_msg(ppi, ch1->fd, pkt, len, t, NULL); ret = wrs_recv_msg(ppi, ch1->fd, pkt, len, t);
else if (ch2->pkt_present) else if (ch2->pkt_present)
ret = wrs_recv_msg(ppi, ch2->fd, pkt, len, t, NULL); ret = wrs_recv_msg(ppi, ch2->fd, pkt, len, t);
if (ret < 0) if (ret < 0)
break; break;
if (pp_diag_allow(ppi, frames, 2)) if (pp_diag_allow(ppi, frames, 2))
...@@ -463,7 +463,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -463,7 +463,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
/* similar to sending raw frames, but w/ different header */ /* similar to sending raw frames, but w/ different header */
ch = ppi->ch + PP_NP_GEN; ch = ppi->ch + PP_NP_GEN;
vhdr->h_proto = htons(ETH_P_1588); vhdr->h_proto = htons(ETH_P_1588);
vhdr->h_tci = htons(ch->peer_vid); /* prio is 0 */ vhdr->h_tci = htons(ppi->peer_vid); /* prio is 0 */
vhdr->h_tpid = htons(0x8100); vhdr->h_tpid = htons(0x8100);
if (drop) if (drop)
hdr->h_proto++; hdr->h_proto++;
......
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