lwip: fix code style issues

Fix various code style issues in the lwIP code.

Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Jerome Forissier 2024-11-07 12:27:57 +01:00 committed by Tom Rini
parent 04b1d84221
commit 356011f7ac
10 changed files with 82 additions and 96 deletions

View File

@ -101,9 +101,6 @@ static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return cp->cmd(cmdtp, flag, argc, argv); return cp->cmd(cmdtp, flag, argc, argv);
} }
U_BOOT_CMD( U_BOOT_CMD(net, 3, 1, do_net, "NET sub-system",
net, 3, 1, do_net,
"NET sub-system",
"list - list available devices\n" "list - list available devices\n"
"stats <device> - dump statistics for specified device\n" "stats <device> - dump statistics for specified device\n");
);

View File

@ -5,41 +5,28 @@
#include <net.h> #include <net.h>
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
U_BOOT_CMD( U_BOOT_CMD(dhcp, 3, 1, do_dhcp,
dhcp, 3, 1, do_dhcp,
"boot image via network using DHCP/TFTP protocol", "boot image via network using DHCP/TFTP protocol",
"[loadAddress] [[hostIPaddr:]bootfilename]" "[loadAddress] [[hostIPaddr:]bootfilename]");
);
#endif #endif
#if defined(CONFIG_CMD_PING) #if defined(CONFIG_CMD_PING)
U_BOOT_CMD( U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host",
ping, 2, 1, do_ping, "pingAddress");
"send ICMP ECHO_REQUEST to network host",
"pingAddress"
);
#endif #endif
#if defined(CONFIG_CMD_TFTPBOOT) #if defined(CONFIG_CMD_TFTPBOOT)
U_BOOT_CMD( U_BOOT_CMD(tftpboot, 3, 0, do_tftpb,
tftpboot, 3, 0, do_tftpb,
"boot image via network using TFTP protocol\n", "boot image via network using TFTP protocol\n",
"[loadAddress] [[hostIPaddr:]bootfilename]" "[loadAddress] [[hostIPaddr:]bootfilename]");
);
#endif #endif
#if defined(CONFIG_CMD_DNS) #if defined(CONFIG_CMD_DNS)
U_BOOT_CMD( U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname",
dns, 3, 1, do_dns, "hostname [envvar]");
"lookup the IP of a hostname",
"hostname [envvar]"
);
#endif #endif
#if defined(CONFIG_CMD_WGET) #if defined(CONFIG_CMD_WGET)
U_BOOT_CMD( U_BOOT_CMD(wget, 3, 1, do_wget, "boot image via network using HTTP protocol",
wget, 3, 1, do_wget, "[loadAddress] URL");
"boot image via network using HTTP protocol",
"[loadAddress] URL"
);
#endif #endif

View File

@ -68,7 +68,7 @@ struct ip_udp_hdr {
u16 udp_dst; /* UDP destination port */ u16 udp_dst; /* UDP destination port */
u16 udp_len; /* Length of UDP packet */ u16 udp_len; /* Length of UDP packet */
u16 udp_xsum; /* Checksum */ u16 udp_xsum; /* Checksum */
} __attribute__((packed)); } __packed;
#define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) #define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr))
#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE) #define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE)
@ -84,13 +84,13 @@ struct ip_udp_hdr {
*/ */
#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) #define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1)
#define ARP_HDR_SIZE (8+20) /* Size assuming ethernet */ #define ARP_HDR_SIZE (8 + 20) /* Size assuming ethernet */
# define ARP_ETHER 1 /* Ethernet hardware address */ # define ARP_ETHER 1 /* Ethernet hardware address */
/* /*
* Maximum packet size; used to allocate packet storage. Use * Maximum packet size; used to allocate packet storage. Use
* the maxium Ethernet frame size as specified by the Ethernet * the maximum Ethernet frame size as specified by the Ethernet
* standard including the 802.1Q tag (VLAN tagging). * standard including the 802.1Q tag (VLAN tagging).
* maximum packet size = 1522 * maximum packet size = 1522
* maximum packet size and multiple of 32 bytes = 1536 * maximum packet size and multiple of 32 bytes = 1536
@ -129,7 +129,7 @@ extern char *pxelinux_configfile;
* @nbytes: Number of bytes to check (normally a multiple of 2) * @nbytes: Number of bytes to check (normally a multiple of 2)
* Return: 16-bit IP checksum * Return: 16-bit IP checksum
*/ */
unsigned compute_ip_checksum(const void *addr, unsigned nbytes); unsigned compute_ip_checksum(const void *addr, unsigned int nbytes);
/** /**
* ip_checksum_ok() - check if a checksum is correct * ip_checksum_ok() - check if a checksum is correct
@ -140,7 +140,7 @@ unsigned compute_ip_checksum(const void *addr, unsigned nbytes);
* @nbytes: Number of bytes to check (normally a multiple of 2) * @nbytes: Number of bytes to check (normally a multiple of 2)
* Return: true if the checksum matches, false if not * Return: true if the checksum matches, false if not
*/ */
int ip_checksum_ok(const void *addr, unsigned nbytes); int ip_checksum_ok(const void *addr, unsigned int nbytes);
/** /**
* add_ip_checksums() - add two IP checksums * add_ip_checksums() - add two IP checksums
@ -150,7 +150,7 @@ int ip_checksum_ok(const void *addr, unsigned nbytes);
* @new_sum: New checksum to add * @new_sum: New checksum to add
* Return: updated 16-bit IP checksum * Return: updated 16-bit IP checksum
*/ */
unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum); unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned int new_sum);
/* /*
* The devname can be either an exact name given by the driver or device tree * The devname can be either an exact name given by the driver or device tree
@ -231,7 +231,7 @@ static inline void net_send_packet(uchar *pkt, int len)
if (DEBUG_NET_PKT_TRACE) if (DEBUG_NET_PKT_TRACE)
print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len); print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len);
/* Currently no way to return errors from eth_send() */ /* Currently no way to return errors from eth_send() */
(void) eth_send(pkt, len); (void)eth_send(pkt, len);
} }
enum eth_recv_flags { enum eth_recv_flags {
@ -327,7 +327,7 @@ struct ethernet_hdr {
u8 et_dest[ARP_HLEN]; /* Destination node */ u8 et_dest[ARP_HLEN]; /* Destination node */
u8 et_src[ARP_HLEN]; /* Source node */ u8 et_src[ARP_HLEN]; /* Source node */
u16 et_protlen; /* Protocol or length */ u16 et_protlen; /* Protocol or length */
} __attribute__((packed)); } __packed;
/* Ethernet header size */ /* Ethernet header size */
#define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr)) #define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr))
@ -445,10 +445,10 @@ void net_process_received_packet(uchar *in_packet, int len);
int update_tftp(ulong addr, char *interface, char *devstring); int update_tftp(ulong addr, char *interface, char *devstring);
/** /**
* env_get_ip() - Convert an environment value to to an ip address * env_get_ip() - Convert an environment value to an ip address
* *
* @var: Environment variable to convert. The value of this variable must be * @var: Environment variable to convert. The value of this variable must be
* in the format format a.b.c.d, where each value is a decimal number from * in the format a.b.c.d, where each value is a decimal number from
* 0 to 255 * 0 to 255
* Return: IP address, or 0 if invalid * Return: IP address, or 0 if invalid
*/ */

View File

@ -43,9 +43,9 @@ struct udevice;
* @param sport source UDP port * @param sport source UDP port
* @param len packet length * @param len packet length
*/ */
typedef void rxhand_f(uchar *pkt, unsigned dport, typedef void rxhand_f(uchar *pkt, unsigned int dport,
struct in_addr sip, unsigned sport, struct in_addr sip, unsigned int sport,
unsigned len); unsigned int len);
/** /**
* An incoming ICMP packet handler. * An incoming ICMP packet handler.
@ -57,8 +57,9 @@ typedef void rxhand_f(uchar *pkt, unsigned dport,
* @param pkt pointer to the ICMP packet data * @param pkt pointer to the ICMP packet data
* @param len packet length * @param len packet length
*/ */
typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport, typedef void rxhand_icmp_f(unsigned type, unsigned int code, unsigned int dport,
struct in_addr sip, unsigned sport, uchar *pkt, unsigned len); struct in_addr sip, unsigned int sport, uchar *pkt,
unsigned int len);
/* /*
* A timeout handler. Called after time interval has expired. * A timeout handler. Called after time interval has expired.
@ -127,7 +128,7 @@ struct e802_hdr {
u8 et_snap2; u8 et_snap2;
u8 et_snap3; u8 et_snap3;
u16 et_prot; /* 802 protocol */ u16 et_prot; /* 802 protocol */
} __attribute__((packed)); } __packed;
/* 802 + SNAP + ethernet header size */ /* 802 + SNAP + ethernet header size */
#define E802_HDR_SIZE (sizeof(struct e802_hdr)) #define E802_HDR_SIZE (sizeof(struct e802_hdr))
@ -141,7 +142,7 @@ struct vlan_ethernet_hdr {
u16 vet_vlan_type; /* PROT_VLAN */ u16 vet_vlan_type; /* PROT_VLAN */
u16 vet_tag; /* TAG of VLAN */ u16 vet_tag; /* TAG of VLAN */
u16 vet_type; /* protocol type */ u16 vet_type; /* protocol type */
} __attribute__((packed)); } __packed;
/* VLAN Ethernet header size */ /* VLAN Ethernet header size */
#define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr)) #define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr))
@ -160,7 +161,7 @@ struct ip_hdr {
u16 ip_sum; /* checksum */ u16 ip_sum; /* checksum */
struct in_addr ip_src; /* Source IP address */ struct in_addr ip_src; /* Source IP address */
struct in_addr ip_dst; /* Destination IP address */ struct in_addr ip_dst; /* Destination IP address */
} __attribute__((packed)); } __packed;
#define IP_OFFS 0x1fff /* ip offset *= 8 */ #define IP_OFFS 0x1fff /* ip offset *= 8 */
#define IP_FLAGS 0xe000 /* first 3 bits */ #define IP_FLAGS 0xe000 /* first 3 bits */
@ -205,8 +206,7 @@ struct arp_hdr {
u8 ar_tha[]; /* Target hardware address */ u8 ar_tha[]; /* Target hardware address */
u8 ar_tpa[]; /* Target protocol address */ u8 ar_tpa[]; /* Target protocol address */
#endif /* 0 */ #endif /* 0 */
} __attribute__((packed)); } __packed;
/* /*
* ICMP stuff (just enough to handle (host) redirect messages) * ICMP stuff (just enough to handle (host) redirect messages)
@ -239,14 +239,14 @@ struct icmp_hdr {
} frag; } frag;
u8 data[0]; u8 data[0];
} un; } un;
} __attribute__((packed)); } __packed;
#define ICMP_HDR_SIZE (sizeof(struct icmp_hdr)) #define ICMP_HDR_SIZE (sizeof(struct icmp_hdr))
#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE) #define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE)
/* /*
* Maximum packet size; used to allocate packet storage. Use * Maximum packet size; used to allocate packet storage. Use
* the maxium Ethernet frame size as specified by the Ethernet * the maximum Ethernet frame size as specified by the Ethernet
* standard including the 802.1Q tag (VLAN tagging). * standard including the 802.1Q tag (VLAN tagging).
* maximum packet size = 1522 * maximum packet size = 1522
* maximum packet size and multiple of 32 bytes = 1536 * maximum packet size and multiple of 32 bytes = 1536
@ -307,6 +307,7 @@ enum proto_t {
NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, FASTBOOT_TCP, NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, FASTBOOT_TCP,
WOL, UDP, NCSI, WGET, RS WOL, UDP, NCSI, WGET, RS
}; };
/* Indicates whether the file name was specified on the command line */ /* Indicates whether the file name was specified on the command line */
extern bool net_boot_file_name_explicit; extern bool net_boot_file_name_explicit;
/* The actual transferred size of the bootfile (in bytes) */ /* The actual transferred size of the bootfile (in bytes) */
@ -364,12 +365,12 @@ void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
/* Callbacks */ /* Callbacks */
rxhand_f *net_get_udp_handler(void); /* Get UDP RX packet handler */ rxhand_f *net_get_udp_handler(void); /* Get UDP RX packet handler */
void net_set_udp_handler(rxhand_f *); /* Set UDP RX packet handler */ void net_set_udp_handler(rxhand_f *f); /* Set UDP RX packet handler */
rxhand_f *net_get_arp_handler(void); /* Get ARP RX packet handler */ rxhand_f *net_get_arp_handler(void); /* Get ARP RX packet handler */
void net_set_arp_handler(rxhand_f *); /* Set ARP RX packet handler */ void net_set_arp_handler(rxhand_f *f); /* Set ARP RX packet handler */
bool arp_is_waiting(void); /* Waiting for ARP reply? */ bool arp_is_waiting(void); /* Waiting for ARP reply? */
void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */ void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
void net_set_timeout_handler(ulong, thand_f *);/* Set timeout handler */ void net_set_timeout_handler(ulong t, thand_f *f);/* Set timeout handler */
/* Network loop state */ /* Network loop state */
enum net_loop_state { enum net_loop_state {
@ -378,6 +379,7 @@ enum net_loop_state {
NETLOOP_SUCCESS, NETLOOP_SUCCESS,
NETLOOP_FAIL NETLOOP_FAIL
}; };
extern enum net_loop_state net_state; extern enum net_loop_state net_state;
static inline void net_set_state(enum net_loop_state state) static inline void net_set_state(enum net_loop_state state)
@ -429,8 +431,8 @@ int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport,
#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_XPL_BUILD) #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_XPL_BUILD)
void nc_start(void); void nc_start(void);
int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port, int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned int dest_port,
unsigned src_port, unsigned len); unsigned int src_port, unsigned int len);
#endif #endif
static __always_inline int eth_is_on_demand_init(void) static __always_inline int eth_is_on_demand_init(void)
@ -522,7 +524,7 @@ void vlan_to_string(ushort x, char *s);
ushort string_to_vlan(const char *s); ushort string_to_vlan(const char *s);
/* read a VLAN id from an environment variable */ /* read a VLAN id from an environment variable */
ushort env_get_vlan(char *); ushort env_get_vlan(char *var);
/* check if serverip is specified in filename from the command line */ /* check if serverip is specified in filename from the command line */
int is_serverip_in_cmd(void); int is_serverip_in_cmd(void);

View File

@ -29,7 +29,8 @@
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ #define LWIP_PLATFORM_ASSERT(x) do { \
printf("Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); } while (0) x, __LINE__, __FILE__); } while (0)
#define atoi(str) (int)dectoul(str, NULL) #define atoi(str) (int)dectoul(str, NULL)

View File

@ -203,7 +203,6 @@ struct netif *net_lwip_new_netif(struct udevice *udev)
struct netif *net_lwip_new_netif_noip(struct udevice *udev) struct netif *net_lwip_new_netif_noip(struct udevice *udev)
{ {
return new_netif(udev, false); return new_netif(udev, false);
} }

View File

@ -39,8 +39,8 @@ static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p,
pbuf_remove_header(p, IP_HLEN) == 0) { pbuf_remove_header(p, IP_HLEN) == 0) {
iecho = (struct icmp_echo_hdr *)p->payload; iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == PING_ID) && if (iecho->id == PING_ID &&
(iecho->seqno == lwip_htons(ctx->seq_num))) { iecho->seqno == lwip_htons(ctx->seq_num)) {
ctx->alive = true; ctx->alive = true;
printf("host %s is alive\n", ipaddr_ntoa(addr)); printf("host %s is alive\n", ipaddr_ntoa(addr));
pbuf_free(p); pbuf_free(p);
@ -93,7 +93,7 @@ static void ping_send_icmp(struct ping_ctx *ctx)
if (!p) if (!p)
return; return;
if ((p->len == p->tot_len) && !p->next) { if (p->len == p->tot_len && !p->next) {
ctx->iecho = (struct icmp_echo_hdr *)p->payload; ctx->iecho = (struct icmp_echo_hdr *)p->payload;
ping_prepare_echo(ctx); ping_prepare_echo(ctx);
raw_sendto(ctx->pcb, p, &ctx->target); raw_sendto(ctx->pcb, p, &ctx->target);
@ -113,7 +113,7 @@ static void ping_send(void *arg)
} }
} }
static int ping_loop(struct udevice *udev, const ip_addr_t* addr) static int ping_loop(struct udevice *udev, const ip_addr_t *addr)
{ {
struct ping_ctx ctx = {}; struct ping_ctx ctx = {};
struct netif *netif; struct netif *netif;

View File

@ -71,7 +71,7 @@ static int tftp_write(void *handle, struct pbuf *p)
struct tftp_ctx *ctx = handle; struct tftp_ctx *ctx = handle;
struct pbuf *q; struct pbuf *q;
for (q = p; q != NULL; q = q->next) { for (q = p; q; q = q->next) {
memcpy((void *)ctx->daddr, q->payload, q->len); memcpy((void *)ctx->daddr, q->payload, q->len);
ctx->daddr += q->len; ctx->daddr += q->len;
ctx->size += q->len; ctx->size += q->len;
@ -187,7 +187,7 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
char *server_port = NULL; char *server_port = NULL;
char *end; char *end;
ip_addr_t srvip; ip_addr_t srvip;
uint16_t port = TFTP_PORT; u16 port = TFTP_PORT;
ulong laddr; ulong laddr;
ulong addr; ulong addr;
int i; int i;
@ -228,7 +228,7 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
if (arg) { if (arg) {
/* Parse [ip:[port:]]fname */ /* Parse [ip:[port:]]fname */
i = 0; i = 0;
while ((*(words + i) = strsep(&arg,":"))) while ((*(words + i) = strsep(&arg, ":")))
i++; i++;
switch (i) { switch (i) {

View File

@ -163,7 +163,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
if (rem < n) if (rem < n)
return -1; return -1;
strncpy(p, server, n); strlcpy(p, server, n);
p += n; p += n;
rem -= n; rem -= n;
if (rem < 1) if (rem < 1)
@ -174,7 +174,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
n = strlen(path); n = strlen(path);
if (rem < n) if (rem < n)
return -1; return -1;
strncpy(p, path, n); strlcpy(p, path, n);
p += n; p += n;
rem -= n; rem -= n;
if (rem < 1) if (rem < 1)