Commit bd2519d6 authored by Adam Wujek's avatar Adam Wujek

lib/ipv4: move ip_status to wrc_globals

make ip_status a pointer to wrc_globals.ip_status
Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent b4eabde9
......@@ -27,6 +27,7 @@ struct dump_info dump_wrpc_info[] = {
DUMP_FIELD(uint32_t, version),
DUMP_FIELD(link_up_status, link_up),
DUMP_FIELD(int, vlan),
DUMP_FIELD(ip_addr_status, ip_status),
DUMP_FIELD(ip_address, ip_addr),
#undef DUMP_STRUCT
......
......@@ -32,6 +32,7 @@ enum dump_type {
dump_type_yes_no,
dump_type_spll_mode,
dump_type_ip_address,
dump_type_ip_addr_status,
};
/* because of the sizeof later on, we need these typedefs */
......@@ -46,6 +47,7 @@ typedef struct {unsigned char addr[4];} ip_address;
typedef uint8_t yes_no;
typedef int spll_mode;
typedef int link_up_status;
typedef int ip_addr_status;
/*
* This is generated with the target compiler, and then linked
......
#ifndef __WRC_GLOBAL_H
#define __WRC_GLOBAL_H
#include <lib/ipv4.h>
#define WRC_G_MAGIC 0xADA5301E
#define WRC_G_VERSION 1
......@@ -10,7 +11,8 @@ struct wrc_global_link {
uint32_t version;
int link_up;
int vlan;
uint8_t ip_addr[4];
int ip_status;
uint8_t ip_addr[INET_ALEN];
};
struct wrc_global {
......
......@@ -91,7 +91,7 @@ int arp_poll(void)
struct wr_sockaddr addr;
int len;
if (ip_status == IP_TRAINING)
if (*ip_status == IP_TRAINING)
return 0; /* can't do ARP w/o an address... */
if ((len = ptpd_netif_recvfrom(arp_socket,
......
......@@ -92,7 +92,7 @@ int process_bootp(uint8_t * buf, int len)
if (memcmp(buf + BOOTP_CHADDR, mac, 6))
return 0;
ip_status = IP_OK_BOOTP;
*ip_status = IP_OK_BOOTP;
setIP(buf + BOOTP_YIADDR);
getIP(ip);
......
......@@ -18,7 +18,7 @@
#include "wrc_ptp.h"
#include "wrc_global.h"
enum ip_status ip_status = IP_TRAINING;
enum ip_status *ip_status = &wrc_global_link.ip_status;
static uint8_t *myIP = wrc_global_link.ip_addr;
/* bootp: bigger buffer, UDP based */
......@@ -101,7 +101,7 @@ static int bootp_poll(void)
len = ptpd_netif_recvfrom(bootp_socket, &addr,
buf, sizeof(buf), NULL);
if (ip_status != IP_TRAINING)
if (*ip_status != IP_TRAINING)
return 0;
/* no extra traffic when abscal is in progress */
......@@ -129,7 +129,7 @@ static int icmp_poll(void)
buf, sizeof(buf), NULL);
if (len <= 0)
return 0;
if (ip_status == IP_TRAINING)
if (*ip_status == IP_TRAINING)
return 0;
/* check the destination IP */
......@@ -174,8 +174,8 @@ int ipv4_poll(void)
{
int ret = 0;
if (*link_status == NETIF_LINK_WENT_UP && ip_status == IP_OK_BOOTP)
ip_status = IP_TRAINING;
if (*link_status == NETIF_LINK_WENT_UP && *ip_status == IP_OK_BOOTP)
*ip_status = IP_TRAINING;
ret = bootp_poll();
ret += icmp_poll();
......@@ -200,7 +200,7 @@ void setIP(unsigned char *IP)
ip = (myIP[0] << 24) | (myIP[1] << 16) | (myIP[2] << 8) | (myIP[3]);
if (ip == 0)
ip_status = IP_TRAINING;
*ip_status = IP_TRAINING;
bootp_retry = 0;
}
......
......@@ -46,7 +46,7 @@ enum ip_status {
IP_OK_BOOTP,
IP_OK_STATIC,
};
extern enum ip_status ip_status;
extern enum ip_status *ip_status;
void setIP(unsigned char *IP);
void getIP(unsigned char *IP);
......
......@@ -255,7 +255,7 @@ int lldp_poll(void)
/* Update only when IP or MAC changed */
/* TODO: or VLAN changed */
if (memcmp(new_mac, old_mac, ETH_ALEN)
|| (HAS_IP && (ip_status != IP_TRAINING)
|| (HAS_IP && (*ip_status != IP_TRAINING)
&& memcmp(new_ipWR, old_ipWR, IPLEN))
) {
/* update LLDP info */
......
......@@ -114,7 +114,7 @@ int netconsole_poll(void)
{
int len;
if (ip_status == IP_TRAINING
if (*ip_status == IP_TRAINING
|| netconsole_status == NETCONSOLE_DISABLED) {
/* can't do netconsole w/o an address...
* or netconsole disabled */
......
......@@ -121,7 +121,7 @@ int syslog_poll(void)
else
s = &((struct wr_data *)ppi->ext_data)->servo_state;
if (ip_status == IP_TRAINING)
if (*ip_status == IP_TRAINING)
return 0;
if (!syslog_addr.daddr)
return 0;
......@@ -263,7 +263,7 @@ void syslog_report(const char *msg)
unsigned char ip[4];
int len;
if (ip_status == IP_TRAINING)
if (*ip_status == IP_TRAINING)
return;
if (!syslog_addr.daddr)
return;
......
......@@ -414,7 +414,7 @@ void print_main_data(void)
getIP(ip);
format_ip(buf, ip);
switch (ip_status) {
switch (*ip_status) {
case IP_TRAINING:
pcprintf(9, 29, C_RED, "BOOTP running ");
break;
......
......@@ -44,7 +44,7 @@ static int cmd_ip(const char *args[])
if (!args[0] || !strcasecmp(args[0], "get")) {
getIP(ip);
} else if (!strcasecmp(args[0], "set") && args[1]) {
ip_status = IP_OK_STATIC;
*ip_status = IP_OK_STATIC;
decode_ip(args[1], ip);
setIP(ip);
#if HAS_EB
......@@ -55,7 +55,7 @@ static int cmd_ip(const char *args[])
}
format_ip(buf, ip);
switch (ip_status) {
switch (*ip_status) {
case IP_TRAINING:
pp_printf("IP-address: in training\n");
break;
......
......@@ -6,7 +6,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <arpa/inet.h> /* ntohl */
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
......@@ -15,6 +14,7 @@
#include <revision.h>
#include <arch/lm32/crt0.h>
#include <dev/netif.h>
#include <lib/ipv4.h>
#include <dump-info.h>
#include "time_lib.h"
......@@ -222,11 +222,26 @@ void dump_one_field(void *addr, struct dump_info *info, char *info_prefix)
break;
case dump_type_ip_address:
for (i = 0; i < 4; i++)
for (i = 0; i < INET_ALEN; i++)
printf("%d%c", ((unsigned char *)p)[i],
i == 3 ? '\n' : '.');
break;
case dump_type_ip_addr_status:
i = wrpc_get_l32(p);
switch(i) {
ENUM_TO_P_IN_CASE(IP_TRAINING, char_p);
ENUM_TO_P_IN_CASE(IP_OK_BOOTP, char_p);
ENUM_TO_P_IN_CASE(IP_OK_STATIC, char_p);
default:
char_p = "Unknown";
}
printf("%d", i);
print_str(char_p);
printf("\n");
break;
case dump_type_link_up_status:
i = wrpc_get_l32(p);
......
......@@ -69,6 +69,7 @@ extern struct spll_fifo_log fifo_log[];
struct wrc_global_link wrc_global_link = {
.version = WRC_G_LINK_VERSION,
.vlan = CONFIG_VLAN_NR,
.ip_status = IP_TRAINING,
};
struct wrc_global wrc_global = {
......
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