raw: separate src and dst addresses

In order to be able to convert to a generic address struct, separate source
and destination address into separate fields.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
master
Jiri Benc 2014-04-11 12:25:52 +02:00 committed by Richard Cochran
parent 8c02ae53f2
commit 3d22154299
2 changed files with 17 additions and 18 deletions

13
ether.h
View File

@ -26,25 +26,24 @@
#define PTP_DST_MAC 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00
#define P2P_DST_MAC 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E
struct eth_addr {
uint8_t dst[MAC_LEN];
uint8_t src[MAC_LEN];
} __attribute__((packed));
typedef uint8_t eth_addr[MAC_LEN];
struct eth_hdr {
struct eth_addr mac;
eth_addr dst;
eth_addr src;
uint16_t type;
} __attribute__((packed));
#define VLAN_HLEN 4
struct vlan_hdr {
struct eth_addr mac;
eth_addr dst;
eth_addr src;
uint16_t tpid;
uint16_t tci;
uint16_t type;
} __attribute__((packed));
#define OFF_ETYPE sizeof(struct eth_addr)
#define OFF_ETYPE (2 * sizeof(eth_addr))
#endif

22
raw.c
View File

@ -45,8 +45,9 @@
struct raw {
struct transport t;
struct eth_addr ptp_addr;
struct eth_addr p2p_addr;
eth_addr src_addr;
eth_addr ptp_addr;
eth_addr p2p_addr;
int vlan;
};
@ -190,14 +191,12 @@ static int raw_open(struct transport *t, const char *name,
struct raw *raw = container_of(t, struct raw, t);
int efd, gfd;
memcpy(raw->ptp_addr.dst, ptp_dst_mac, MAC_LEN);
memcpy(raw->p2p_addr.dst, p2p_dst_mac, MAC_LEN);
memcpy(raw->ptp_addr, ptp_dst_mac, MAC_LEN);
memcpy(raw->p2p_addr, p2p_dst_mac, MAC_LEN);
if (sk_interface_macaddr(name, raw->ptp_addr.src, MAC_LEN))
if (sk_interface_macaddr(name, raw->src_addr, MAC_LEN))
goto no_mac;
memcpy(raw->p2p_addr.src, raw->ptp_addr.src, MAC_LEN);
efd = open_socket(name, 1);
if (efd < 0)
goto no_event;
@ -277,9 +276,10 @@ static int raw_send(struct transport *t, struct fdarray *fda, int event, int pee
hdr = (struct eth_hdr *) ptr;
if (peer)
memcpy(&hdr->mac, &raw->p2p_addr, sizeof(hdr->mac));
memcpy(&hdr->dst, &raw->p2p_addr, MAC_LEN);
else
memcpy(&hdr->mac, &raw->ptp_addr, sizeof(hdr->mac));
memcpy(&hdr->dst, &raw->ptp_addr, MAC_LEN);
memcpy(&hdr->src, &raw->src_addr, MAC_LEN);
hdr->type = htons(ETH_P_1588);
@ -303,14 +303,14 @@ static void raw_release(struct transport *t)
static int raw_physical_addr(struct transport *t, uint8_t *addr)
{
struct raw *raw = container_of(t, struct raw, t);
memcpy(addr, raw->ptp_addr.src, MAC_LEN);
memcpy(addr, raw->src_addr, MAC_LEN);
return MAC_LEN;
}
static int raw_protocol_addr(struct transport *t, uint8_t *addr)
{
struct raw *raw = container_of(t, struct raw, t);
memcpy(addr, raw->ptp_addr.src, MAC_LEN);
memcpy(addr, raw->src_addr, MAC_LEN);
return MAC_LEN;
}