Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-12 Thread Simon Glass
Hi Vyacheslav,

On Mon, 12 Sept 2022 at 04:11, Vyacheslav Mitrofanov V
 wrote:
>
> On Mon, 2022-09-12 at 10:23 +0300, Ramon Fried wrote:
> > «Внимание! Данное письмо от внешнего адресата!»
> >
> > On Tue, Sep 6, 2022 at 6:10 PM Viacheslav Mitrofanov
> >  wrote:
> > > This patch is a collection of basic primitives that are
> > > prerequisite for
> > > further IPv6 implementation.
> > >
> > > There are structures definition such as IPv6 header, UDP header
> > > (for TFTP), ICMPv6 header. There are auxiliary defines such as
> > > protocol
> > > codes, padding, struct size and etc. Also here are functions
> > > prototypes
> > > and its empty implementation that will be used as API for further
> > > patches.
> > > Here are variables declaration such as IPv6 address of our host,
> > > gateway, ipv6 server.
> > >
> > > Signed-off-by: Viacheslav Mitrofanov 
> > > ---
> > >  include/net6.h | 369
> > > +
> > >  net/net6.c |  31 +
> > >  2 files changed, 400 insertions(+)
> > >  create mode 100644 include/net6.h
> > >  create mode 100644 net/net6.c
> > >
> > > diff --git a/include/net6.h b/include/net6.h
> > > new file mode 100644
> > > index 00..80236bd5ac
> > > --- /dev/null
> > > +++ b/include/net6.h
> > > @@ -0,0 +1,369 @@
> > > +/* SPDX-License-Identifier: GPL-2.0+ */
> > > +/*
> > > + * Copyright (C) 2013 Allied Telesis Labs NZ
> > > + * Chris Packham, 
> > > + *
> > > + * Copyright (C) 2022 YADRO
> > > + * Viacheslav Mitrofanov 
> > > + */
> > > +
> > > +#ifndef __NET6_H__
> > > +#define __NET6_H__
> > > +
> > > +#include 
> > > +#include 
> > > +
> > > +/* struct in6_addr - 128 bits long IPv6 address */
> > > +struct in6_addr {
> > > +   union {
> > > +   u8  u6_addr8[16];
> > > +   __be16  u6_addr16[8];
> > > +   __be32  u6_addr32[4];
> > > +   } in6_u;
> > > +
> > > +#define s6_addrin6_u.u6_addr8
> > > +#define s6_addr16  in6_u.u6_addr16
> > > +#define s6_addr32  in6_u.u6_addr32
> > > +};
> > > +
> > > +#define IN6ADDRSZ  sizeof(struct in6_addr)
> > > +#define INETHADDRSZsizeof(net_ethaddr)
> > > +
> > > +#define PROT_IP6   0x86DD  /* IPv6 protocol */
> > > +#define PROT_ICMPV658  /* ICMPv6 protocol*/
> > > +
> > > +#define IPV6_ADDRSCOPE_INTF0x01
> > > +#define IPV6_ADDRSCOPE_LINK0x02
> > > +#define IPV6_ADDRSCOPE_AMDIN   0x04
> > > +#define IPV6_ADDRSCOPE_SITE0x05
> > > +#define IPV6_ADDRSCOPE_ORG 0x08
> > > +#define IPV6_ADDRSCOPE_GLOBAL  0x0E
> > > +
> > > +#define USE_IP6_CMD_PARAM  "-ipv6"
> > > +
> > > +/**
> > > + * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
> > > + *
> > > + * IPv6 packet header as defined in RFC 2460.
> > > + */
> > > +struct ip6_hdr {
> > > +#if defined(__LITTLE_ENDIAN_BITFIELD)
> > > +   u8  priority:4,
> > > +   version:4;
> > > +#elif defined(__BIG_ENDIAN_BITFIELD)
> > > +   u8  version:4,
> > > +   priority:4;
> > > +#else
> > > +#error  "Please fix "
> > > +#endif
> > > +   u8  flow_lbl[3];
> > > +   __be16  payload_len;
> > > +   u8  nexthdr;
> > > +   u8  hop_limit;
> > > +   struct in6_addr saddr;
> > > +   struct in6_addr daddr;
> > > +};
> > > +#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> > > +
> > > +/* struct udp_hdr - User Datagram Protocol header */
> > > +struct udp_hdr {
> > > +   u16 udp_src;/* UDP source
> > > port  */
> > > +   u16 udp_dst;/* UDP destination
> > > port */
> > > +   u16 udp_len;/* Length of UDP
> > > packet */
> > > +   u16 udp_xsum;   /*
> > > Checksum */
> > > +} __packed;
> > > +
> > > +/*
> > > + * Handy for static initialisations of struct in6_addr, atlhough
> > > the
> > > + * c99 '= { 0 }' idiom might work depending on you compiler.
> > > + */
> > > +#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
> > > + 0x00, 0x00, 0x00, 0x00, \
> > > + 0x00, 0x00, 0x00, 0x00, \
> > > + 0x00, 0x00, 0x00, 0x00 } } }
> > > +
> > > +#define IPV6_LINK_LOCAL_PREFIX 0xfe80
> > > +
> > > +/* hop limit for neighbour discovery packets */
> > > +#define IPV6_NDISC_HOPLIMIT 255
> > > +#define NDISC_TIMEOUT  5000UL
> > > +#define NDISC_TIMEOUT_COUNT 3
> > > +
> > > +/* struct icmp6hdr - Internet Control Message Protocol header for
> > > IPV6 */
> > > +struct icmp6hdr {
> > > +   u8  icmp6_type;
> > > +#define IPV6_ICMP_ECHO_REQUEST 128
> > > +#define IPV6_ICMP_ECHO_REPLY   129
> > > +#define IPV6_NDISC_ROUTER_SOLICITATION 133
> > > +#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
> > > +#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
> > > +#define 

Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-12 Thread Vyacheslav Mitrofanov V
On Mon, 2022-09-12 at 10:23 +0300, Ramon Fried wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On Tue, Sep 6, 2022 at 6:10 PM Viacheslav Mitrofanov
>  wrote:
> > This patch is a collection of basic primitives that are
> > prerequisite for
> > further IPv6 implementation.
> > 
> > There are structures definition such as IPv6 header, UDP header
> > (for TFTP), ICMPv6 header. There are auxiliary defines such as
> > protocol
> > codes, padding, struct size and etc. Also here are functions
> > prototypes
> > and its empty implementation that will be used as API for further
> > patches.
> > Here are variables declaration such as IPv6 address of our host,
> > gateway, ipv6 server.
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > ---
> >  include/net6.h | 369
> > +
> >  net/net6.c |  31 +
> >  2 files changed, 400 insertions(+)
> >  create mode 100644 include/net6.h
> >  create mode 100644 net/net6.c
> > 
> > diff --git a/include/net6.h b/include/net6.h
> > new file mode 100644
> > index 00..80236bd5ac
> > --- /dev/null
> > +++ b/include/net6.h
> > @@ -0,0 +1,369 @@
> > +/* SPDX-License-Identifier: GPL-2.0+ */
> > +/*
> > + * Copyright (C) 2013 Allied Telesis Labs NZ
> > + * Chris Packham, 
> > + *
> > + * Copyright (C) 2022 YADRO
> > + * Viacheslav Mitrofanov 
> > + */
> > +
> > +#ifndef __NET6_H__
> > +#define __NET6_H__
> > +
> > +#include 
> > +#include 
> > +
> > +/* struct in6_addr - 128 bits long IPv6 address */
> > +struct in6_addr {
> > +   union {
> > +   u8  u6_addr8[16];
> > +   __be16  u6_addr16[8];
> > +   __be32  u6_addr32[4];
> > +   } in6_u;
> > +
> > +#define s6_addrin6_u.u6_addr8
> > +#define s6_addr16  in6_u.u6_addr16
> > +#define s6_addr32  in6_u.u6_addr32
> > +};
> > +
> > +#define IN6ADDRSZ  sizeof(struct in6_addr)
> > +#define INETHADDRSZsizeof(net_ethaddr)
> > +
> > +#define PROT_IP6   0x86DD  /* IPv6 protocol */
> > +#define PROT_ICMPV658  /* ICMPv6 protocol*/
> > +
> > +#define IPV6_ADDRSCOPE_INTF0x01
> > +#define IPV6_ADDRSCOPE_LINK0x02
> > +#define IPV6_ADDRSCOPE_AMDIN   0x04
> > +#define IPV6_ADDRSCOPE_SITE0x05
> > +#define IPV6_ADDRSCOPE_ORG 0x08
> > +#define IPV6_ADDRSCOPE_GLOBAL  0x0E
> > +
> > +#define USE_IP6_CMD_PARAM  "-ipv6"
> > +
> > +/**
> > + * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
> > + *
> > + * IPv6 packet header as defined in RFC 2460.
> > + */
> > +struct ip6_hdr {
> > +#if defined(__LITTLE_ENDIAN_BITFIELD)
> > +   u8  priority:4,
> > +   version:4;
> > +#elif defined(__BIG_ENDIAN_BITFIELD)
> > +   u8  version:4,
> > +   priority:4;
> > +#else
> > +#error  "Please fix "
> > +#endif
> > +   u8  flow_lbl[3];
> > +   __be16  payload_len;
> > +   u8  nexthdr;
> > +   u8  hop_limit;
> > +   struct in6_addr saddr;
> > +   struct in6_addr daddr;
> > +};
> > +#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> > +
> > +/* struct udp_hdr - User Datagram Protocol header */
> > +struct udp_hdr {
> > +   u16 udp_src;/* UDP source
> > port  */
> > +   u16 udp_dst;/* UDP destination
> > port */
> > +   u16 udp_len;/* Length of UDP
> > packet */
> > +   u16 udp_xsum;   /*
> > Checksum */
> > +} __packed;
> > +
> > +/*
> > + * Handy for static initialisations of struct in6_addr, atlhough
> > the
> > + * c99 '= { 0 }' idiom might work depending on you compiler.
> > + */
> > +#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00 } } }
> > +
> > +#define IPV6_LINK_LOCAL_PREFIX 0xfe80
> > +
> > +/* hop limit for neighbour discovery packets */
> > +#define IPV6_NDISC_HOPLIMIT 255
> > +#define NDISC_TIMEOUT  5000UL
> > +#define NDISC_TIMEOUT_COUNT 3
> > +
> > +/* struct icmp6hdr - Internet Control Message Protocol header for
> > IPV6 */
> > +struct icmp6hdr {
> > +   u8  icmp6_type;
> > +#define IPV6_ICMP_ECHO_REQUEST 128
> > +#define IPV6_ICMP_ECHO_REPLY   129
> > +#define IPV6_NDISC_ROUTER_SOLICITATION 133
> > +#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
> > +#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
> > +#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
> > +#define IPV6_NDISC_REDIRECT137
> > +   u8  icmp6_code;
> > +   __be16  icmp6_cksum;
> > +
> > +   /* ICMPv6 data */
> > +   union {
> > +   __be32  un_data32[1];
> > +   __be16  un_data16[2];
> > +   u8  un_data8[4];
> > +
> > +   

Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-12 Thread Ramon Fried
On Tue, Sep 6, 2022 at 6:10 PM Viacheslav Mitrofanov
 wrote:
>
> This patch is a collection of basic primitives that are prerequisite for
> further IPv6 implementation.
>
> There are structures definition such as IPv6 header, UDP header
> (for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
> codes, padding, struct size and etc. Also here are functions prototypes
> and its empty implementation that will be used as API for further patches.
> Here are variables declaration such as IPv6 address of our host,
> gateway, ipv6 server.
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
>  include/net6.h | 369 +
>  net/net6.c |  31 +
>  2 files changed, 400 insertions(+)
>  create mode 100644 include/net6.h
>  create mode 100644 net/net6.c
>
> diff --git a/include/net6.h b/include/net6.h
> new file mode 100644
> index 00..80236bd5ac
> --- /dev/null
> +++ b/include/net6.h
> @@ -0,0 +1,369 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2013 Allied Telesis Labs NZ
> + * Chris Packham, 
> + *
> + * Copyright (C) 2022 YADRO
> + * Viacheslav Mitrofanov 
> + */
> +
> +#ifndef __NET6_H__
> +#define __NET6_H__
> +
> +#include 
> +#include 
> +
> +/* struct in6_addr - 128 bits long IPv6 address */
> +struct in6_addr {
> +   union {
> +   u8  u6_addr8[16];
> +   __be16  u6_addr16[8];
> +   __be32  u6_addr32[4];
> +   } in6_u;
> +
> +#define s6_addrin6_u.u6_addr8
> +#define s6_addr16  in6_u.u6_addr16
> +#define s6_addr32  in6_u.u6_addr32
> +};
> +
> +#define IN6ADDRSZ  sizeof(struct in6_addr)
> +#define INETHADDRSZsizeof(net_ethaddr)
> +
> +#define PROT_IP6   0x86DD  /* IPv6 protocol */
> +#define PROT_ICMPV658  /* ICMPv6 protocol*/
> +
> +#define IPV6_ADDRSCOPE_INTF0x01
> +#define IPV6_ADDRSCOPE_LINK0x02
> +#define IPV6_ADDRSCOPE_AMDIN   0x04
> +#define IPV6_ADDRSCOPE_SITE0x05
> +#define IPV6_ADDRSCOPE_ORG 0x08
> +#define IPV6_ADDRSCOPE_GLOBAL  0x0E
> +
> +#define USE_IP6_CMD_PARAM  "-ipv6"
> +
> +/**
> + * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
> + *
> + * IPv6 packet header as defined in RFC 2460.
> + */
> +struct ip6_hdr {
> +#if defined(__LITTLE_ENDIAN_BITFIELD)
> +   u8  priority:4,
> +   version:4;
> +#elif defined(__BIG_ENDIAN_BITFIELD)
> +   u8  version:4,
> +   priority:4;
> +#else
> +#error  "Please fix "
> +#endif
> +   u8  flow_lbl[3];
> +   __be16  payload_len;
> +   u8  nexthdr;
> +   u8  hop_limit;
> +   struct in6_addr saddr;
> +   struct in6_addr daddr;
> +};
> +#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> +
> +/* struct udp_hdr - User Datagram Protocol header */
> +struct udp_hdr {
> +   u16 udp_src;/* UDP source port  */
> +   u16 udp_dst;/* UDP destination port */
> +   u16 udp_len;/* Length of UDP packet */
> +   u16 udp_xsum;   /* Checksum */
> +} __packed;
> +
> +/*
> + * Handy for static initialisations of struct in6_addr, atlhough the
> + * c99 '= { 0 }' idiom might work depending on you compiler.
> + */
> +#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00 } } }
> +
> +#define IPV6_LINK_LOCAL_PREFIX 0xfe80
> +
> +/* hop limit for neighbour discovery packets */
> +#define IPV6_NDISC_HOPLIMIT 255
> +#define NDISC_TIMEOUT  5000UL
> +#define NDISC_TIMEOUT_COUNT 3
> +
> +/* struct icmp6hdr - Internet Control Message Protocol header for IPV6 */
> +struct icmp6hdr {
> +   u8  icmp6_type;
> +#define IPV6_ICMP_ECHO_REQUEST 128
> +#define IPV6_ICMP_ECHO_REPLY   129
> +#define IPV6_NDISC_ROUTER_SOLICITATION 133
> +#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
> +#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
> +#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
> +#define IPV6_NDISC_REDIRECT137
> +   u8  icmp6_code;
> +   __be16  icmp6_cksum;
> +
> +   /* ICMPv6 data */
> +   union {
> +   __be32  un_data32[1];
> +   __be16  un_data16[2];
> +   u8  un_data8[4];
> +
> +   /* struct icmpv6_echo - echo request/reply message format */
> +   struct icmpv6_echo {
> +   __be16  identifier;
> +   __be16  sequence;
> +   } u_echo;
> +
> +   /* struct icmpv6_nd_advt - Neighbor Advertisement format */
> +   struct icmpv6_nd_advt {
> +#if defined(__LITTLE_ENDIAN_BITFIELD)
> +

Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-09 Thread Simon Glass
On Thu, 8 Sept 2022 at 05:59, Viacheslav Mitrofanov
 wrote:
>
> This patch is a collection of basic primitives that are prerequisite for
> further IPv6 implementation.
>
> There are structures definition such as IPv6 header, UDP header
> (for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
> codes, padding, struct size and etc. Also here are functions prototypes
> and its empty implementation that will be used as API for further patches.
> Here are variables declaration such as IPv6 address of our host,
> gateway, ipv6 server.
>
> Series-changes: 3
> - Added functions and structures descriptions
> - Removed enums ND_OPT_*. It will be moved into further patches
> - Substituted -1 for error codes
>
> Series-changes: 4
> - Changed functions and structures description style
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
>  include/net6.h | 369 +
>  net/net6.c |  31 +
>  2 files changed, 400 insertions(+)
>  create mode 100644 include/net6.h
>  create mode 100644 net/net6.c

Reviewed-by: Simon Glass 


[PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-08 Thread Viacheslav Mitrofanov
This patch is a collection of basic primitives that are prerequisite for
further IPv6 implementation.

There are structures definition such as IPv6 header, UDP header
(for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
codes, padding, struct size and etc. Also here are functions prototypes
and its empty implementation that will be used as API for further patches.
Here are variables declaration such as IPv6 address of our host,
gateway, ipv6 server.

Series-changes: 3
- Added functions and structures descriptions
- Removed enums ND_OPT_*. It will be moved into further patches
- Substituted -1 for error codes

Series-changes: 4
- Changed functions and structures description style

Signed-off-by: Viacheslav Mitrofanov 
---
 include/net6.h | 369 +
 net/net6.c |  31 +
 2 files changed, 400 insertions(+)
 create mode 100644 include/net6.h
 create mode 100644 net/net6.c

diff --git a/include/net6.h b/include/net6.h
new file mode 100644
index 00..9200eae04e
--- /dev/null
+++ b/include/net6.h
@@ -0,0 +1,369 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2013 Allied Telesis Labs NZ
+ * Chris Packham, 
+ *
+ * Copyright (C) 2022 YADRO
+ * Viacheslav Mitrofanov 
+ */
+
+#ifndef __NET6_H__
+#define __NET6_H__
+
+#include 
+#include 
+
+/* struct in6_addr - 128 bits long IPv6 address */
+struct in6_addr {
+   union {
+   u8  u6_addr8[16];
+   __be16  u6_addr16[8];
+   __be32  u6_addr32[4];
+   } in6_u;
+
+#define s6_addrin6_u.u6_addr8
+#define s6_addr16  in6_u.u6_addr16
+#define s6_addr32  in6_u.u6_addr32
+};
+
+#define IN6ADDRSZ  sizeof(struct in6_addr)
+#define INETHADDRSZsizeof(net_ethaddr)
+
+#define PROT_IP6   0x86DD  /* IPv6 protocol */
+#define PROT_ICMPV658  /* ICMPv6 protocol*/
+
+#define IPV6_ADDRSCOPE_INTF0x01
+#define IPV6_ADDRSCOPE_LINK0x02
+#define IPV6_ADDRSCOPE_AMDIN   0x04
+#define IPV6_ADDRSCOPE_SITE0x05
+#define IPV6_ADDRSCOPE_ORG 0x08
+#define IPV6_ADDRSCOPE_GLOBAL  0x0E
+
+#define USE_IP6_CMD_PARAM  "-ipv6"
+
+/**
+ * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
+ *
+ * IPv6 packet header as defined in RFC 2460.
+ */
+struct ip6_hdr {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   u8  priority:4,
+   version:4;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+   u8  version:4,
+   priority:4;
+#else
+#error  "Please fix "
+#endif
+   u8  flow_lbl[3];
+   __be16  payload_len;
+   u8  nexthdr;
+   u8  hop_limit;
+   struct in6_addr saddr;
+   struct in6_addr daddr;
+};
+#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
+
+/* struct udp_hdr - User Datagram Protocol header */
+struct udp_hdr {
+   u16 udp_src;/* UDP source port  */
+   u16 udp_dst;/* UDP destination port */
+   u16 udp_len;/* Length of UDP packet */
+   u16 udp_xsum;   /* Checksum */
+} __packed;
+
+/*
+ * Handy for static initialisations of struct in6_addr, atlhough the
+ * c99 '= { 0 }' idiom might work depending on you compiler.
+ */
+#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00 } } }
+
+#define IPV6_LINK_LOCAL_PREFIX 0xfe80
+
+/* hop limit for neighbour discovery packets */
+#define IPV6_NDISC_HOPLIMIT 255
+#define NDISC_TIMEOUT  5000UL
+#define NDISC_TIMEOUT_COUNT 3
+
+/* struct icmp6hdr - Internet Control Message Protocol header for IPV6 */
+struct icmp6hdr {
+   u8  icmp6_type;
+#define IPV6_ICMP_ECHO_REQUEST 128
+#define IPV6_ICMP_ECHO_REPLY   129
+#define IPV6_NDISC_ROUTER_SOLICITATION 133
+#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
+#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
+#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
+#define IPV6_NDISC_REDIRECT137
+   u8  icmp6_code;
+   __be16  icmp6_cksum;
+
+   /* ICMPv6 data */
+   union {
+   __be32  un_data32[1];
+   __be16  un_data16[2];
+   u8  un_data8[4];
+
+   /* struct icmpv6_echo - echo request/reply message format */
+   struct icmpv6_echo {
+   __be16  identifier;
+   __be16  sequence;
+   } u_echo;
+
+   /* struct icmpv6_nd_advt - Neighbor Advertisement format */
+   struct icmpv6_nd_advt {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   __be32  reserved:5,
+   override:1,
+  

Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-07 Thread Simon Glass
Hi Viacheslav,

On Tue, 6 Sept 2022 at 09:10, Viacheslav Mitrofanov
 wrote:
>
> This patch is a collection of basic primitives that are prerequisite for
> further IPv6 implementation.
>
> There are structures definition such as IPv6 header, UDP header
> (for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
> codes, padding, struct size and etc. Also here are functions prototypes
> and its empty implementation that will be used as API for further patches.
> Here are variables declaration such as IPv6 address of our host,
> gateway, ipv6 server.
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
>  include/net6.h | 369 +
>  net/net6.c |  31 +
>  2 files changed, 400 insertions(+)
>  create mode 100644 include/net6.h
>  create mode 100644 net/net6.c
>

Reviewed-by: Simon Glass 

BTW the comment style changed a few years ago - the @param is gone and
we now use Return(s) instead of @return

Regards,
Simon


[PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-06 Thread Viacheslav Mitrofanov
This patch is a collection of basic primitives that are prerequisite for
further IPv6 implementation.

There are structures definition such as IPv6 header, UDP header
(for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
codes, padding, struct size and etc. Also here are functions prototypes
and its empty implementation that will be used as API for further patches.
Here are variables declaration such as IPv6 address of our host,
gateway, ipv6 server.

Signed-off-by: Viacheslav Mitrofanov 
---
 include/net6.h | 369 +
 net/net6.c |  31 +
 2 files changed, 400 insertions(+)
 create mode 100644 include/net6.h
 create mode 100644 net/net6.c

diff --git a/include/net6.h b/include/net6.h
new file mode 100644
index 00..80236bd5ac
--- /dev/null
+++ b/include/net6.h
@@ -0,0 +1,369 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2013 Allied Telesis Labs NZ
+ * Chris Packham, 
+ *
+ * Copyright (C) 2022 YADRO
+ * Viacheslav Mitrofanov 
+ */
+
+#ifndef __NET6_H__
+#define __NET6_H__
+
+#include 
+#include 
+
+/* struct in6_addr - 128 bits long IPv6 address */
+struct in6_addr {
+   union {
+   u8  u6_addr8[16];
+   __be16  u6_addr16[8];
+   __be32  u6_addr32[4];
+   } in6_u;
+
+#define s6_addrin6_u.u6_addr8
+#define s6_addr16  in6_u.u6_addr16
+#define s6_addr32  in6_u.u6_addr32
+};
+
+#define IN6ADDRSZ  sizeof(struct in6_addr)
+#define INETHADDRSZsizeof(net_ethaddr)
+
+#define PROT_IP6   0x86DD  /* IPv6 protocol */
+#define PROT_ICMPV658  /* ICMPv6 protocol*/
+
+#define IPV6_ADDRSCOPE_INTF0x01
+#define IPV6_ADDRSCOPE_LINK0x02
+#define IPV6_ADDRSCOPE_AMDIN   0x04
+#define IPV6_ADDRSCOPE_SITE0x05
+#define IPV6_ADDRSCOPE_ORG 0x08
+#define IPV6_ADDRSCOPE_GLOBAL  0x0E
+
+#define USE_IP6_CMD_PARAM  "-ipv6"
+
+/**
+ * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
+ *
+ * IPv6 packet header as defined in RFC 2460.
+ */
+struct ip6_hdr {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   u8  priority:4,
+   version:4;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+   u8  version:4,
+   priority:4;
+#else
+#error  "Please fix "
+#endif
+   u8  flow_lbl[3];
+   __be16  payload_len;
+   u8  nexthdr;
+   u8  hop_limit;
+   struct in6_addr saddr;
+   struct in6_addr daddr;
+};
+#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
+
+/* struct udp_hdr - User Datagram Protocol header */
+struct udp_hdr {
+   u16 udp_src;/* UDP source port  */
+   u16 udp_dst;/* UDP destination port */
+   u16 udp_len;/* Length of UDP packet */
+   u16 udp_xsum;   /* Checksum */
+} __packed;
+
+/*
+ * Handy for static initialisations of struct in6_addr, atlhough the
+ * c99 '= { 0 }' idiom might work depending on you compiler.
+ */
+#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00 } } }
+
+#define IPV6_LINK_LOCAL_PREFIX 0xfe80
+
+/* hop limit for neighbour discovery packets */
+#define IPV6_NDISC_HOPLIMIT 255
+#define NDISC_TIMEOUT  5000UL
+#define NDISC_TIMEOUT_COUNT 3
+
+/* struct icmp6hdr - Internet Control Message Protocol header for IPV6 */
+struct icmp6hdr {
+   u8  icmp6_type;
+#define IPV6_ICMP_ECHO_REQUEST 128
+#define IPV6_ICMP_ECHO_REPLY   129
+#define IPV6_NDISC_ROUTER_SOLICITATION 133
+#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
+#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
+#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
+#define IPV6_NDISC_REDIRECT137
+   u8  icmp6_code;
+   __be16  icmp6_cksum;
+
+   /* ICMPv6 data */
+   union {
+   __be32  un_data32[1];
+   __be16  un_data16[2];
+   u8  un_data8[4];
+
+   /* struct icmpv6_echo - echo request/reply message format */
+   struct icmpv6_echo {
+   __be16  identifier;
+   __be16  sequence;
+   } u_echo;
+
+   /* struct icmpv6_nd_advt - Neighbor Advertisement format */
+   struct icmpv6_nd_advt {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   __be32  reserved:5,
+   override:1,
+   solicited:1,
+   router:1,
+   reserved2:24;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+   __be32  router:1,
+   

Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-08-31 Thread Simon Glass
Hi Viacheslav,

On Tue, 30 Aug 2022 at 07:00, Viacheslav Mitrofanov
 wrote:
>
> This patch is a collection of basic primitives that are prerequisite for
> further IPv6 implementation.
>
> There are structures definition such as IPv6 header, UDP header
> (for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
> codes, padding, struct size and etc. Also here are functions prototypes
> and its empty implementation that will be used as API for further patches.
> Here are variables declaration such as IPv6 address of our host,
> gateway, ipv6 server.
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
>  include/net6.h | 256 +
>  net/net6.c |  33 +++
>  2 files changed, 289 insertions(+)
>  create mode 100644 include/net6.h
>  create mode 100644 net/net6.c

Please comment structs and functions.

Regards,
Simon


[PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-08-30 Thread Viacheslav Mitrofanov
This patch is a collection of basic primitives that are prerequisite for
further IPv6 implementation.

There are structures definition such as IPv6 header, UDP header
(for TFTP), ICMPv6 header. There are auxiliary defines such as protocol
codes, padding, struct size and etc. Also here are functions prototypes
and its empty implementation that will be used as API for further patches.
Here are variables declaration such as IPv6 address of our host,
gateway, ipv6 server.

Signed-off-by: Viacheslav Mitrofanov 
---
 include/net6.h | 256 +
 net/net6.c |  33 +++
 2 files changed, 289 insertions(+)
 create mode 100644 include/net6.h
 create mode 100644 net/net6.c

diff --git a/include/net6.h b/include/net6.h
new file mode 100644
index 00..71072d1416
--- /dev/null
+++ b/include/net6.h
@@ -0,0 +1,256 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2013 Allied Telesis Labs NZ
+ * Chris Packham, 
+ *
+ * Copyright (C) 2022 YADRO
+ * Viacheslav Mitrofanov 
+ */
+
+#ifndef __NET6_H__
+#define __NET6_H__
+
+#include 
+#include 
+
+struct in6_addr {
+   union {
+   u8  u6_addr8[16];
+   __be16  u6_addr16[8];
+   __be32  u6_addr32[4];
+   } in6_u;
+
+#define s6_addrin6_u.u6_addr8
+#define s6_addr16  in6_u.u6_addr16
+#define s6_addr32  in6_u.u6_addr32
+};
+
+#define PROT_IP6   0x86DD  /* IPv6 protocol */
+
+#define IN6ADDRSZ  sizeof(struct in6_addr)
+#define INETHADDRSZsizeof(net_ethaddr)
+
+#define IPV6_ADDRSCOPE_INTF0x01
+#define IPV6_ADDRSCOPE_LINK0x02
+#define IPV6_ADDRSCOPE_AMDIN   0x04
+#define IPV6_ADDRSCOPE_SITE0x05
+#define IPV6_ADDRSCOPE_ORG 0x08
+#define IPV6_ADDRSCOPE_GLOBAL  0x0E
+
+#define USE_IP6_CMD_PARAM  "-ipv6"
+
+/**
+ * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
+ *
+ * IPv6 packet header as defined in RFC 2460.
+ */
+struct ip6_hdr {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   u8  priority:4,
+   version:4;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+   u8  version:4,
+   priority:4;
+#else
+#error  "Please fix "
+#endif
+   u8  flow_lbl[3];
+   __be16  payload_len;
+   u8  nexthdr;
+   u8  hop_limit;
+   struct in6_addr saddr;
+   struct in6_addr daddr;
+};
+
+struct udp_hdr {
+   u16 udp_src;/* UDP source port  */
+   u16 udp_dst;/* UDP destination port */
+   u16 udp_len;/* Length of UDP packet */
+   u16 udp_xsum;   /* Checksum */
+} __packed;
+#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
+
+/* Handy for static initialisations of struct in6_addr, atlhough the
+ * c99 '= { 0 }' idiom might work depending on you compiler.
+ */
+#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00 } } }
+
+#define IPV6_LINK_LOCAL_PREFIX 0xfe80
+
+enum {
+   __ND_OPT_PREFIX_INFO_END= 0,
+   ND_OPT_SOURCE_LL_ADDR   = 1,
+   ND_OPT_TARGET_LL_ADDR   = 2,
+   ND_OPT_PREFIX_INFO  = 3,
+   ND_OPT_REDIRECT_HDR = 4,
+   ND_OPT_MTU  = 5,
+   __ND_OPT_MAX
+};
+
+/* ICMPv6 */
+#define IPPROTO_ICMPV6 58
+/* hop limit for neighbour discovery packets */
+#define IPV6_NDISC_HOPLIMIT 255
+#define NDISC_TIMEOUT  5000UL
+#define NDISC_TIMEOUT_COUNT 3
+
+struct icmp6hdr {
+   u8  icmp6_type;
+#define IPV6_ICMP_ECHO_REQUEST 128
+#define IPV6_ICMP_ECHO_REPLY   129
+#define IPV6_NDISC_ROUTER_SOLICITATION 133
+#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
+#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
+#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
+#define IPV6_NDISC_REDIRECT137
+   u8  icmp6_code;
+   __be16  icmp6_cksum;
+
+   union {
+   __be32  un_data32[1];
+   __be16  un_data16[2];
+   u8  un_data8[4];
+
+   struct icmpv6_echo {
+   __be16  identifier;
+   __be16  sequence;
+   } u_echo;
+
+   struct icmpv6_nd_advt {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+   __be32  reserved:5,
+   override:1,
+   solicited:1,
+   router:1,
+   reserved2:24;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+   __be32  router:1,
+   solicited:1,
+