Commit 15c56131 authored by Alessandro Rubini's avatar Alessandro Rubini

general: remove use of needless NP function

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 225b2f27
......@@ -92,7 +92,7 @@ void sim_main_loop(struct pp_globals *ppg)
sim_set_global_DS(ppi);
tmp_ns = 1000LL * 1000LL * pp_state_machine(ppi,
ppi->rx_ptp, i - NP(ppi)->ptp_offset);
ppi->rx_ptp, i - ppi->ptp_offset);
if (tmp_ns < delay_ns)
delay_ns = tmp_ns;
......
......@@ -146,8 +146,8 @@ int main(int argc, char **argv)
if (ppi->proto == PPSI_PROTO_RAW)
pp_printf("Warning: simulator doesn't support raw "
"ethernet. Using UDP\n");
NP(ppi)->ch[PP_NP_GEN].fd = -1;
NP(ppi)->ch[PP_NP_EVT].fd = -1;
ppi->ch[PP_NP_GEN].fd = -1;
ppi->ch[PP_NP_EVT].fd = -1;
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->n_ops = &DEFAULT_NET_OPS;
if (pp_sim_is_master(ppi))
......
......@@ -54,7 +54,7 @@ void unix_main_loop(struct pp_globals *ppg)
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->proto == PPSI_PROTO_RAW)
NP(ppi)->ptp_offset = ETH_HLEN;
ppi->ptp_offset = ETH_HLEN;
/*
* The main loop here is based on select. While we are not
......@@ -107,8 +107,8 @@ void unix_main_loop(struct pp_globals *ppg)
int tmp_d;
ppi = INST(ppg, j);
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
(NP(ppi)->ch[PP_NP_EVT].pkt_present)) {
if ((ppi->ch[PP_NP_GEN].pkt_present) ||
(ppi->ch[PP_NP_EVT].pkt_present)) {
i = __recv_and_count(ppi, ppi->rx_frame,
PP_MAX_FRAME_LENGTH - 4,
......@@ -131,7 +131,7 @@ void unix_main_loop(struct pp_globals *ppg)
}
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
i - ppi->ptp_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
......
......@@ -84,8 +84,8 @@ int main(int argc, char **argv)
for (i = 0; i < ppg->nlinks; i++) {
ppi = INST(ppg, i);
NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1;
ppi->ch[PP_NP_EVT].fd = -1;
ppi->ch[PP_NP_GEN].fd = -1;
ppi->glbs = ppg;
ppi->vlans_array_len = CONFIG_VLAN_ARRAY_SIZE,
......
......@@ -93,7 +93,7 @@ void wrs_main_loop(struct pp_globals *ppg)
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->proto == PPSI_PROTO_RAW)
NP(ppi)->ptp_offset = ETH_HLEN;
ppi->ptp_offset = ETH_HLEN;
/*
* The main loop here is based on select. While we are not
......@@ -148,8 +148,8 @@ void wrs_main_loop(struct pp_globals *ppg)
int tmp_d;
ppi = INST(ppg, j);
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
(NP(ppi)->ch[PP_NP_EVT].pkt_present)) {
if ((ppi->ch[PP_NP_GEN].pkt_present) ||
(ppi->ch[PP_NP_EVT].pkt_present)) {
i = __recv_and_count(ppi, ppi->rx_frame,
PP_MAX_FRAME_LENGTH - 4,
......@@ -172,7 +172,7 @@ void wrs_main_loop(struct pp_globals *ppg)
}
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
i - ppi->ptp_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
......
......@@ -199,8 +199,8 @@ int main(int argc, char **argv)
}
for (i = 0; i < ppg->nlinks; i++) {
ppi = INST(ppg, i);
NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1;
ppi->ch[PP_NP_EVT].fd = -1;
ppi->ch[PP_NP_GEN].fd = -1;
ppi->glbs = ppg;
ppi->vlans_array_len = CONFIG_VLAN_ARRAY_SIZE;
......
......@@ -103,12 +103,12 @@ 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;
return ptp_payload - ppi->ptp_offset;
}
static inline void *pp_get_payload(struct pp_instance *ppi, void *frame_ptr)
{
return frame_ptr + NP(ppi)->ptp_offset;
return frame_ptr + ppi->ptp_offset;
}
extern void pp_prepare_pointers(struct pp_instance *ppi);
......
......@@ -24,7 +24,7 @@ void bare_main_loop(struct pp_instance *ppi)
{
int delay_ms;
NP(ppi)->ptp_offset = 14;
ppi->ptp_offset = 14;
/*
* The main loop here is based on select. While we are not
......@@ -44,11 +44,11 @@ void bare_main_loop(struct pp_instance *ppi)
again:
FD_ZERO(&set);
FD_SET(NP(ppi)->ch[PP_NP_GEN].fd, &set);
FD_SET(NP(ppi)->ch[PP_NP_EVT].fd, &set);
maxfd = NP(ppi)->ch[PP_NP_GEN].fd;
if (NP(ppi)->ch[PP_NP_EVT].fd > maxfd)
maxfd = NP(ppi)->ch[PP_NP_EVT].fd;
FD_SET(ppi->ch[PP_NP_GEN].fd, &set);
FD_SET(ppi->ch[PP_NP_EVT].fd, &set);
maxfd = ppi->ch[PP_NP_GEN].fd;
if (ppi->ch[PP_NP_EVT].fd > maxfd)
maxfd = ppi->ch[PP_NP_EVT].fd;
i = sys_select(maxfd + 1, &set, NULL, NULL, &tv);
if (i < 0 && bare_errno != 4 /* EINTR */)
......@@ -77,6 +77,6 @@ void bare_main_loop(struct pp_instance *ppi)
goto again;
delay_ms = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
i - ppi->ptp_offset);
}
}
......@@ -38,7 +38,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + NP(ppi)->ptp_offset,
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + ppi->ptp_offset,
&ppi->last_snt_time, chtype, 0) < msglen) {
pp_diag(ppi, frames, 1, "%s(%d) Message can't be sent\n",
pp_msg_names[msgtype], msgtype);
......
......@@ -24,7 +24,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* Clock identity comes from mac address with 0xff:0xfe intermixed */
id = (unsigned char *)&DSDEF(ppi)->clockIdentity;
mac = NP(ppi)->ch[PP_NP_GEN].addr;
mac = ppi->ch[PP_NP_GEN].addr;
id[0] = mac[0];
id[1] = mac[1];
id[2] = mac[2];
......
......@@ -18,7 +18,7 @@ static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
if (t)
ppi->t_ops->get(ppi, t);
ret = sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
ret = sys_recv(ppi->ch[PP_NP_GEN].fd, pkt, len, 0);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("recv: ", pkt, ret, t);
return ret;
......@@ -35,12 +35,12 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, 6);
/* raw socket implementation always uses gen socket */
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, 6);
memcpy(hdr->h_source, ppi->ch[PP_NP_GEN].addr, 6);
if (t)
ppi->t_ops->get(ppi, t);
ret = sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
ret = sys_send(ppi->ch[chtype].fd, pkt, len, 0);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
......@@ -82,9 +82,9 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
if (sys_ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
goto err_out;
memcpy(NP(ppi)->ch[PP_NP_GEN].addr,
memcpy(ppi->ch[PP_NP_GEN].addr,
ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
memcpy(NP(ppi)->ch[PP_NP_EVT].addr,
memcpy(ppi->ch[PP_NP_EVT].addr,
ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
/* bind */
......@@ -106,8 +106,8 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
sys_setsockopt(sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
&pmr, sizeof(pmr)); /* lazily ignore errors */
NP(ppi)->ch[PP_NP_GEN].fd = sock;
NP(ppi)->ch[PP_NP_EVT].fd = sock;
ppi->ch[PP_NP_GEN].fd = sock;
ppi->ch[PP_NP_EVT].fd = sock;
/* make timestamps available through recvmsg() -- FIXME: hw? */
sys_setsockopt(sock, SOL_SOCKET, SO_TIMESTAMP,
......@@ -128,14 +128,14 @@ err_out:
static int bare_net_exit(struct pp_instance *ppi)
{
return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR);
return sys_shutdown(ppi->ch[PP_NP_GEN].fd, SHUT_RDWR);
}
/* This function must be able to be called twice, and clean-up internally */
static int bare_net_init(struct pp_instance *ppi)
{
/* Here, socket may not be 0 (do we have stdin even if bare) */
if (NP(ppi)->ch[PP_NP_GEN].fd)
if (ppi->ch[PP_NP_GEN].fd)
bare_net_exit(ppi);
/* The buffer is inside ppi, but we need to set pointers and align */
......
......@@ -145,7 +145,7 @@ static int sim_net_recv(struct pp_instance *ppi, void *pkt, int len,
if (data->n_pending <= 0)
return 0;
ch = &(NP(ppi)->ch[data->pending->chtype]);
ch = &(ppi->ch[data->pending->chtype]);
ret = -1;
if (ch->pkt_present > 0) {
......@@ -181,12 +181,12 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
PP_SLAVE_GEN_PORT :
PP_SLAVE_EVT_PORT);
addr.sin_addr.s_addr = NP(ppi)->mcast_addr;
addr.sin_addr.s_addr = ppi->mcast_addr;
if (t)
ppi->t_ops->get(ppi, t);
ret = sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0,
ret = sendto(ppi->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr, sizeof(struct sockaddr_in));
if (pp_diag_allow(ppi, frames, 2))
dump_payloadpkt("send: ", pkt, len, t);
......@@ -219,7 +219,7 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
pending.delay_ns = data->n_delay.t_prop_ns + jit_ns;
insert_pending(SIM_PPG_ARCH(ppi->glbs), &pending);
NP(data->other_ppi)->ch[chtype].pkt_present++;
data->other_ppi->ch[chtype].pkt_present++;
return ret;
}
......@@ -230,11 +230,11 @@ static int sim_net_exit(struct pp_instance *ppi)
/* only UDP */
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
fd = NP(ppi)->ch[i].fd;
fd = ppi->ch[i].fd;
if (fd < 0)
continue;
close(fd);
NP(ppi)->ch[i].fd = -1;
ppi->ch[i].fd = -1;
}
return 0;
}
......@@ -253,7 +253,7 @@ static int sim_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
if (sock < 0)
goto err_out;
NP(ppi)->ch[chtype].fd = sock;
ppi->ch[chtype].fd = sock;
temp = 1; /* allow address reuse */
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &temp, sizeof(int)) < 0)
......@@ -278,21 +278,21 @@ static int sim_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
sizeof(struct sockaddr_in)) < 0)
goto err_out;
NP(ppi)->ch[chtype].fd = sock;
ppi->ch[chtype].fd = sock;
/*
* Standard ppsi state machine is designed to drop packets coming from
* itself, based on the clockIdentity. This hack avoids this behaviour,
* changing the clockIdentity of the master.
*/
if (pp_sim_is_master(ppi))
memset(NP(ppi)->ch[chtype].addr, 111, 1);
memset(ppi->ch[chtype].addr, 111, 1);
return 0;
err_out:
pp_printf("%s: %s: %s\n", __func__, context, strerror(errno));
if (sock >= 0)
close(sock);
NP(ppi)->ch[chtype].fd = -1;
ppi->ch[chtype].fd = -1;
return -1;
}
......@@ -300,7 +300,7 @@ static int sim_net_init(struct pp_instance *ppi)
{
int i;
if (NP(ppi)->ch[0].fd > 0)
if (ppi->ch[0].fd > 0)
sim_net_exit(ppi);
/* The buffer is inside ppi, but we need to set pointers and align */
......
......@@ -108,7 +108,7 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
switch(ppi->proto) {
case PPSI_PROTO_RAW:
fd = NP(ppi)->ch[PP_NP_GEN].fd;
fd = ppi->ch[PP_NP_GEN].fd;
ret = unix_recv_msg(ppi, fd, pkt, len, t);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
......@@ -118,8 +118,8 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
case PPSI_PROTO_UDP:
/* we can return one frame only, always handle EVT msgs
* before GEN */
ch1 = &(NP(ppi)->ch[PP_NP_EVT]);
ch2 = &(NP(ppi)->ch[PP_NP_GEN]);
ch1 = &(ppi->ch[PP_NP_EVT]);
ch2 = &(ppi->ch[PP_NP_GEN]);
ret = -1;
if (ch1->pkt_present)
......@@ -159,12 +159,12 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
/* raw socket implementation always uses gen socket */
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, ETH_ALEN);
memcpy(hdr->h_source, ppi->ch[PP_NP_GEN].addr, ETH_ALEN);
if (t)
ppi->t_ops->get(ppi, t);
ret = send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0);
ret = send(ppi->ch[PP_NP_GEN].fd, hdr, len, 0);
if (pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
......@@ -173,12 +173,12 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
addr.sin_family = AF_INET;
addr.sin_port = htons(chtype == PP_NP_GEN
? PP_GEN_PORT : PP_EVT_PORT);
addr.sin_addr.s_addr = NP(ppi)->mcast_addr;
addr.sin_addr.s_addr = ppi->mcast_addr;
if (t)
ppi->t_ops->get(ppi, t);
ret = sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0,
ret = sendto(ppi->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr,
sizeof(struct sockaddr_in));
if (pp_diag_allow(ppi, frames, 2))
......@@ -221,7 +221,7 @@ static int unix_open_ch_raw(struct pp_instance *ppi, char *ifname, int chtype)
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
goto err_out;
memcpy(NP(ppi)->ch[chtype].addr, ifr.ifr_hwaddr.sa_data, 6);
memcpy(ppi->ch[chtype].addr, ifr.ifr_hwaddr.sa_data, 6);
/* bind */
memset(&addr_ll, 0, sizeof(addr));
......@@ -242,7 +242,7 @@ static int unix_open_ch_raw(struct pp_instance *ppi, char *ifname, int chtype)
setsockopt(sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
&pmr, sizeof(pmr)); /* lazily ignore errors */
NP(ppi)->ch[chtype].fd = sock;
ppi->ch[chtype].fd = sock;
/* make timestamps available through recvmsg() -- FIXME: hw? */
setsockopt(sock, SOL_SOCKET, SO_TIMESTAMP,
......@@ -254,7 +254,7 @@ err_out:
pp_printf("%s: %s: %s\n", __func__, context, strerror(errno));
if (sock >= 0)
close(sock);
NP(ppi)->ch[chtype].fd = -1;
ppi->ch[chtype].fd = -1;
return -1;
}
......@@ -274,7 +274,7 @@ static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
if (sock < 0)
goto err_out;
NP(ppi)->ch[chtype].fd = sock;
ppi->ch[chtype].fd = sock;
/* hw interface information */
memset(&ifr, 0, sizeof(ifr));
......@@ -287,7 +287,7 @@ static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
goto err_out;
memcpy(NP(ppi)->ch[chtype].addr, ifr.ifr_hwaddr.sa_data, 6);
memcpy(ppi->ch[chtype].addr, ifr.ifr_hwaddr.sa_data, 6);
context = "ioctl(SIOCGIFADDR)";
if (ioctl(sock, SIOCGIFADDR, &ifr) < 0)
goto err_out;
......@@ -322,7 +322,7 @@ static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
context = addr_str; errno = EINVAL;
if (!inet_aton(addr_str, &net_addr))
goto err_out;
NP(ppi)->mcast_addr = net_addr.s_addr;
ppi->mcast_addr = net_addr.s_addr;
/* multicast sends only on specified interface */
imr.imr_multiaddr.s_addr = net_addr.s_addr;
......@@ -359,14 +359,14 @@ static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
&temp, sizeof(int)) < 0)
goto err_out;
NP(ppi)->ch[chtype].fd = sock;
ppi->ch[chtype].fd = sock;
return 0;
err_out:
pp_printf("%s: %s: %s\n", __func__, context, strerror(errno));
if (sock >= 0)
close(sock);
NP(ppi)->ch[chtype].fd = -1;
ppi->ch[chtype].fd = -1;
return -1;
}
......@@ -381,7 +381,7 @@ static int unix_net_init(struct pp_instance *ppi)
{
int i;
if (NP(ppi)->ch[0].fd > 0)
if (ppi->ch[0].fd > 0)
unix_net_exit(ppi);
/* The buffer is inside ppi, but we need to set pointers and align */
......@@ -425,30 +425,30 @@ static int unix_net_exit(struct pp_instance *ppi)
switch(ppi->proto) {
case PPSI_PROTO_RAW:
fd = NP(ppi)->ch[PP_NP_GEN].fd;
fd = ppi->ch[PP_NP_GEN].fd;
if (fd > 0) {
close(fd);
NP(ppi)->ch[PP_NP_GEN].fd = -1;
ppi->ch[PP_NP_GEN].fd = -1;
}
return 0;
case PPSI_PROTO_UDP:
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
fd = NP(ppi)->ch[i].fd;
fd = ppi->ch[i].fd;
if (fd < 0)
continue;
/* Close General Multicast */
imr.imr_multiaddr.s_addr = NP(ppi)->mcast_addr;
imr.imr_multiaddr.s_addr = ppi->mcast_addr;
imr.imr_interface.s_addr = htonl(INADDR_ANY);
setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&imr, sizeof(struct ip_mreq));
close(fd);
NP(ppi)->ch[i].fd = -1;
ppi->ch[i].fd = -1;
}
NP(ppi)->mcast_addr = 0;
ppi->mcast_addr = 0;
return 0;
case PPSI_PROTO_VLAN:
/* FIXME */
......@@ -488,8 +488,8 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
/* Use either fd that is valid, irrespective of ether/udp */
for (k = 0; k < 2; k++) {
NP(ppi)->ch[k].pkt_present = 0;
fd_to_set = NP(ppi)->ch[k].fd;
ppi->ch[k].pkt_present = 0;
fd_to_set = ppi->ch[k].fd;
if (fd_to_set < 0)
continue;
......@@ -510,18 +510,18 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = INST(ppg, j);
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
int fd = ppi->ch[PP_NP_GEN].fd;
if (fd >= 0 && FD_ISSET(fd, &set)) {
ret++;
NP(ppi)->ch[PP_NP_GEN].pkt_present = 1;
ppi->ch[PP_NP_GEN].pkt_present = 1;
}
fd = NP(ppi)->ch[PP_NP_EVT].fd;
fd = ppi->ch[PP_NP_EVT].fd;
if (fd >= 0 && FD_ISSET(fd, &set)) {
ret++;
NP(ppi)->ch[PP_NP_EVT].pkt_present = 1;
ppi->ch[PP_NP_EVT].pkt_present = 1;
}
}
return ret;
......
......@@ -26,10 +26,10 @@ static int wrpc_open_ch(struct pp_instance *ppi)
return -1;
ptpd_netif_get_hw_addr(sock, &mac);
memcpy(NP(ppi)->ch[PP_NP_EVT].addr, &mac, sizeof(mac_addr_t));
NP(ppi)->ch[PP_NP_EVT].custom = sock;
memcpy(NP(ppi)->ch[PP_NP_GEN].addr, &mac, sizeof(mac_addr_t));
NP(ppi)->ch[PP_NP_GEN].custom = sock;
memcpy(ppi->ch[PP_NP_EVT].addr, &mac, sizeof(mac_addr_t));
ppi->ch[PP_NP_EVT].custom = sock;
memcpy(ppi->ch[PP_NP_GEN].addr, &mac, sizeof(mac_addr_t));
ppi->ch[PP_NP_GEN].custom = sock;
return 0;
}
......@@ -42,7 +42,7 @@ static int wrpc_net_recv(struct pp_instance *ppi, void *pkt, int len,
wr_socket_t *sock;
wr_timestamp_t wr_ts;
wr_sockaddr_t addr;
sock = NP(ppi)->ch[PP_NP_EVT].custom;
sock = ppi->ch[PP_NP_EVT].custom;
got = ptpd_netif_recvfrom(sock, &addr, pkt, len, &wr_ts);
if (t) {
......@@ -74,7 +74,7 @@ static int wrpc_net_send(struct pp_instance *ppi, void *pkt, int len,
wr_socket_t *sock;
wr_timestamp_t wr_ts;
wr_sockaddr_t addr;
sock = NP(ppi)->ch[PP_NP_EVT].custom;
sock = ppi->ch[PP_NP_EVT].custom;
addr.ethertype = ETH_P_1588;
memcpy(&addr.mac, PP_MCAST_MACADDRESS, sizeof(mac_addr_t));
......@@ -102,14 +102,14 @@ static int wrpc_net_send(struct pp_instance *ppi, void *pkt, int len,
static int wrpc_net_exit(struct pp_instance *ppi)
{
ptpd_netif_close_socket(NP(ppi)->ch[PP_NP_EVT].custom);
ptpd_netif_close_socket(ppi->ch[PP_NP_EVT].custom);
return 0;
}
/* This function must be able to be called twice, and clean-up internally */
static int wrpc_net_init(struct pp_instance *ppi)
{
if (NP(ppi)->ch[PP_NP_EVT].custom)
if (ppi->ch[PP_NP_EVT].custom)
wrpc_net_exit(ppi);
pp_prepare_pointers(ppi);
wrpc_open_ch(ppi);
......
......@@ -171,7 +171,7 @@ static int wrs_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
struct cmsghdr *cmsg;
struct scm_timestamping *sts = NULL;
s = (struct wrs_socket*)NP(ppi)->ch[PP_NP_GEN].arch_data;
s = (struct wrs_socket*)ppi->ch[PP_NP_GEN].arch_data;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &entry;
......@@ -249,7 +249,7 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
switch(ppi->proto) {
case PPSI_PROTO_RAW:
fd = NP(ppi)->ch[PP_NP_GEN].fd;
fd = ppi->ch[PP_NP_GEN].fd;
ret = wrs_recv_msg(ppi, fd, pkt, len, t);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
......@@ -258,8 +258,8 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
case PPSI_PROTO_UDP:
/* UDP: always handle EVT msgs before GEN */
ch1 = &(NP(ppi)->ch[PP_NP_EVT]);
ch2 = &(NP(ppi)->ch[PP_NP_GEN]);
ch1 = &(ppi->ch[PP_NP_EVT]);
ch2 = &(ppi->ch[PP_NP_GEN]);
if (ch1->pkt_present)
ret = wrs_recv_msg(ppi, ch1->fd, pkt, len, t);
......@@ -385,7 +385,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
struct wrs_socket *s;
int ret, fd, drop;
s = (struct wrs_socket *)NP(ppi)->ch[PP_NP_GEN].arch_data;
s = (struct wrs_socket *)ppi->ch[PP_NP_GEN].arch_data;
/*
* To fake a packet loss, we must corrupt the frame; we need
......@@ -396,14 +396,14 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
switch (ppi->proto) {
case PPSI_PROTO_RAW:
fd = NP(ppi)->ch[PP_NP_GEN].fd;
fd = ppi->ch[PP_NP_GEN].fd;
hdr->h_proto = htons(ETH_P_1588);
if (drop)
hdr->h_proto++;
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
/* raw socket implementation always uses gen socket */
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, ETH_ALEN);
memcpy(hdr->h_source, ppi->ch[PP_NP_GEN].addr, ETH_ALEN);
if (t)
ppi->t_ops->get(ppi, t);
......@@ -422,11 +422,11 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
return ret;
case PPSI_PROTO_UDP:
fd = NP(ppi)->ch[chtype].fd;
fd = ppi->ch[chtype].fd;
addr.sin_family = AF_INET;
addr.sin_port = htons(chtype == PP_NP_GEN
? PP_GEN_PORT : PP_EVT_PORT);
addr.sin_addr.s_addr = NP(ppi)->mcast_addr;
addr.sin_addr.s_addr = ppi->mcast_addr;
if (drop)
addr.sin_port = 3200;
ret = sendto(fd, pkt, len, 0, (struct sockaddr *)&addr,
......@@ -496,7 +496,7 @@ static int wrs_net_init(struct pp_instance *ppi)
int r, i;
struct hal_port_state *p;
if (NP(ppi)->ch[PP_NP_GEN].arch_data)
if (ppi->ch[PP_NP_GEN].arch_data)
wrs_net_exit(ppi);
/* Generic OS work is done by standard Unix stuff */
......@@ -530,15 +530,15 @@ static int wrs_net_init(struct pp_instance *ppi)
s->dmtd_phase_valid = 0;
NP(ppi)->ch[PP_NP_GEN].arch_data = s;
NP(ppi)->ch[PP_NP_EVT].arch_data = s;
ppi->ch[PP_NP_GEN].arch_data = s;
ppi->ch[PP_NP_EVT].arch_data = s;
tmo_init(&s->dmtd_update_tmo, DMTD_UPDATE_INTERVAL);
for (i = PP_NP_GEN, r = 0; i <= PP_NP_EVT && r == 0; i++)
r = wrs_enable_timestamps(ppi, NP(ppi)->ch[i].fd);
r = wrs_enable_timestamps(ppi, ppi->ch[i].fd);
if (r) {
NP(ppi)->ch[PP_NP_GEN].arch_data = NULL;
NP(ppi)->ch[PP_NP_EVT].arch_data = NULL;
ppi->ch[PP_NP_GEN].arch_data = NULL;
ppi->ch[PP_NP_EVT].arch_data = NULL;
free(s);
}
return r;
......@@ -547,9 +547,9 @@ static int wrs_net_init(struct pp_instance *ppi)
static int wrs_net_exit(struct pp_instance *ppi)
{
unix_net_ops.exit(ppi);
free(NP(ppi)->ch[PP_NP_GEN].arch_data);
NP(ppi)->ch[PP_NP_GEN].arch_data = NULL;
NP(ppi)->ch[PP_NP_EVT].arch_data = NULL;
free(ppi->ch[PP_NP_GEN].arch_data);
ppi->ch[PP_NP_GEN].arch_data = NULL;
ppi->ch[PP_NP_EVT].arch_data = NULL;
return 0;
}
......
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