Commit c7401a84 authored by Alessandro Rubini's avatar Alessandro Rubini

net: all poll functions return 0/1

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7e3805a6
......@@ -88,17 +88,20 @@ static int process_arp(uint8_t * buf, int len)
return ARP_END;
}
void arp_poll(void)
int arp_poll(void)
{
uint8_t buf[ARP_END + 100];
struct wr_sockaddr addr;
int len;
if (ip_status == IP_TRAINING)
return; /* can't do ARP w/o an address... */
return 0; /* can't do ARP w/o an address... */
if ((len = ptpd_netif_recvfrom(arp_socket,
&addr, buf, sizeof(buf), 0)) > 0)
&addr, buf, sizeof(buf), 0)) > 0) {
if ((len = process_arp(buf, len)) > 0)
ptpd_netif_sendto(arp_socket, &addr, buf, len, 0);
return 1;
}
return 0;
}
......@@ -51,8 +51,8 @@ static struct wrpc_socket *rdate_socket;
void __attribute__((weak)) syslog_init(void)
{ }
void __attribute__((weak)) syslog_poll(int l_status)
{ }
int __attribute__((weak)) syslog_poll(int l_status)
{ return 0; }
unsigned int ipv4_checksum(unsigned short *buf, int shorts)
{
......@@ -94,11 +94,11 @@ static int bootp_retry = 0;
static uint32_t bootp_tics;
/* receive bootp through the UDP mechanism */
static void bootp_poll(void)
static int bootp_poll(void)
{
struct wr_sockaddr addr;
uint8_t buf[400];
int len;
int len, ret = 0;
if (!bootp_tics) /* first time ever */
bootp_tics = timer_get_tics() - 1;
......@@ -107,20 +107,21 @@ static void bootp_poll(void)
buf, sizeof(buf), NULL);
if (ip_status != IP_TRAINING)
return;
return 0;
if (len > 0)
process_bootp(buf, len);
ret = process_bootp(buf, len);
if (time_before(timer_get_tics(), bootp_tics))
return;
return ret;
len = prepare_bootp(&addr, buf, ++bootp_retry);
ptpd_netif_sendto(bootp_socket, &addr, buf, len, 0);
bootp_tics = timer_get_tics() + TICS_PER_SECOND;
return 1;
}
static void icmp_poll(void)
static int icmp_poll(void)
{
struct wr_sockaddr addr;
uint8_t buf[128];
......@@ -129,15 +130,16 @@ static void icmp_poll(void)
len = ptpd_netif_recvfrom(icmp_socket, &addr,
buf, sizeof(buf), NULL);
if (len <= 0)
return;
return 0;
if (ip_status == IP_TRAINING)
return;
return 0;
if ((len = process_icmp(buf, len)) > 0)
ptpd_netif_sendto(icmp_socket, &addr, buf, len, 0);
return 1;
}
static void rdate_poll(void)
static int rdate_poll(void)
{
struct wr_sockaddr addr;
uint64_t secs;
......@@ -148,7 +150,7 @@ static void rdate_poll(void)
len = ptpd_netif_recvfrom(rdate_socket, &addr,
buf, sizeof(buf), NULL);
if (len <= 0)
return;
return 0;
shw_pps_gen_get_time(&secs, NULL);
result = htonl((uint32_t)(secs + 2208988800LL));
......@@ -159,20 +161,24 @@ static void rdate_poll(void)
fill_udp(buf, len, NULL);
ptpd_netif_sendto(rdate_socket, &addr, buf, len, 0);
return 1;
}
void ipv4_poll(int l_status)
int ipv4_poll(int l_status)
{
int ret = 0;
if (l_status == LINK_WENT_UP && ip_status == IP_OK_BOOTP)
ip_status = IP_TRAINING;
bootp_poll();
ret = bootp_poll();
ret += icmp_poll();
icmp_poll();
ret += rdate_poll();
rdate_poll();
ret += syslog_poll(l_status);
syslog_poll(l_status);
return ret != 0;
}
void getIP(unsigned char *IP)
......
......@@ -34,13 +34,13 @@
#define UDP_END (UDP_CHECKSUM+2)
void ipv4_init(void);
void ipv4_poll(int l_status);
int ipv4_poll(int l_status);
/* Internal to IP stack: */
unsigned int ipv4_checksum(unsigned short *buf, int shorts);
void arp_init(void);
void arp_poll(void);
int arp_poll(void);
enum ip_status {
IP_TRAINING,
......@@ -66,6 +66,6 @@ struct wr_udp_addr {
void fill_udp(uint8_t * buf, int len, struct wr_udp_addr *uaddr);
void syslog_init(void);
void syslog_poll(int l_status);
int syslog_poll(int l_status);
#endif
......@@ -55,7 +55,7 @@ DEFINE_WRC_COMMAND(mac) = {
};
void syslog_poll(int l_status)
int syslog_poll(int l_status)
{
struct wr_sockaddr addr;
char buf[256];
......@@ -67,9 +67,9 @@ void syslog_poll(int l_status)
int len = 0;
if (ip_status == IP_TRAINING)
return;
return 0;
if (!syslog_addr.daddr)
return;
return 0;
if (!tics) {
/* first time ever, or new syslog server */
......@@ -101,7 +101,7 @@ void syslog_poll(int l_status)
goto send;
}
return;
return 0;
send:
len += UDP_END;
......@@ -109,5 +109,6 @@ send:
fill_udp((void *)buf, len, &syslog_addr);
memcpy(&addr.mac, syslog_mac, 6);
ptpd_netif_sendto(syslog_socket, &addr, buf, len, 0);
return 1;
}
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