Re: [PATCH 16/16] bsd: Added conf-INET6 option to enable IPv6 support

2018-08-13 Thread Nadav Har'El
On Tue, Aug 7, 2018 at 5:49 AM, Charles Myers 
wrote:

> Signed-off-by: Charles Myers 
> ---
>  Makefile | 27 ++-
>  bsd/net.cc   | 23 +++-
>  bsd/porting/netport.h|  4 +++
>  bsd/sys/dev/xen/netfront/netfront.cc |  4 +++
>  conf/base.mk |  5 
>  include/api/netinet/in.h | 52 +++---
> --
>  6 files changed, 64 insertions(+), 51 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index d5b6fda..317e727 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -347,7 +347,7 @@ $(out)/bsd/%.o: INCLUDES += -isystem bsd/
>  # for machine/
>  $(out)/bsd/%.o: INCLUDES += -isystem bsd/$(arch)
>
> -configuration-defines = conf-preempt conf-debug_memory conf-logger_debug
> +configuration-defines = conf-preempt conf-debug_memory conf-logger_debug
> conf-INET6
>
>  configuration = $(foreach cf,$(configuration-defines), \
>-D$(cf:conf-%=CONF_%)=$($(cf)))
> @@ -611,6 +611,31 @@ bsd += bsd/sys/netinet/cc/cc_cubic.o
>  bsd += bsd/sys/netinet/cc/cc_htcp.o
>  bsd += bsd/sys/netinet/cc/cc_newreno.o
>  bsd += bsd/sys/netinet/arpcache.o
> +ifeq ($(conf-INET6), 1)
> +bsd += bsd/sys/netinet6/dest6.o
> +bsd += bsd/sys/netinet6/frag6.o
> +bsd += bsd/sys/netinet6/icmp6.o
> +bsd += bsd/sys/netinet6/in6.o
> +bsd += bsd/sys/netinet6/in6_cksum.o
> +bsd += bsd/sys/netinet6/in6_ifattach.o
> +bsd += bsd/sys/netinet6/in6_mcast.o
> +bsd += bsd/sys/netinet6/in6_pcb.o
> +bsd += bsd/sys/netinet6/in6_proto.o
> +bsd += bsd/sys/netinet6/in6_rmx.o
> +bsd += bsd/sys/netinet6/in6_src.o
> +bsd += bsd/sys/netinet6/ip6_forward.o
> +bsd += bsd/sys/netinet6/ip6_id.o
> +bsd += bsd/sys/netinet6/ip6_input.o
> +bsd += bsd/sys/netinet6/ip6_output.o
> +bsd += bsd/sys/netinet6/mld6.o
> +bsd += bsd/sys/netinet6/nd6.o
> +bsd += bsd/sys/netinet6/nd6_nbr.o
> +bsd += bsd/sys/netinet6/nd6_rtr.o
> +bsd += bsd/sys/netinet6/raw_ip6.o
> +bsd += bsd/sys/netinet6/route6.o
> +bsd += bsd/sys/netinet6/scope6.o
> +bsd += bsd/sys/netinet6/udp6_usrreq.o
> +endif
>  bsd += bsd/sys/xdr/xdr.o
>  bsd += bsd/sys/xdr/xdr_array.o
>  bsd += bsd/sys/xdr/xdr_mem.o
> diff --git a/bsd/net.cc b/bsd/net.cc
> index f548e09..3fe334a 100644
> --- a/bsd/net.cc
> +++ b/bsd/net.cc
> @@ -24,6 +24,11 @@
>  #include 
>  #include 
>  #include 
> +#ifdef INET6
> +#include 
> +#include 
> +#include 
> +#endif
>
>  /* Generation of ip ids */
>  void ip_initid(void);
> @@ -31,6 +36,10 @@ void ip_initid(void);
>  extern "C" {
>  /* AF_INET */
>  extern  struct domain inetdomain;
> +#ifdef INET6
> +/* AF_INET6 */
> +extern  struct domain inet6domain;
> +#endif
>  /* AF_ROUTE */
>  extern  struct domain routedomain;
>  /* AF_NETLINK */
> @@ -55,12 +64,20 @@ void net_init(void)
>  vnet_pfil_init();
>  domaininit(NULL);
>  OSV_DOMAIN_SET(inet);
> +#ifdef INET6
> +OSV_DOMAIN_SET(inet6);
> +#endif
>  OSV_DOMAIN_SET(route);
>  OSV_DOMAIN_SET(netlink);
>  rts_init();
>  route_init();
>  vnet_route_init();
>  netlink_init();
> +#ifdef INET6
> +ip6_init2(NULL);
> +mld_init(NULL);
> +vnet_mld_init(NULL);
> +#endif
>  ipport_tick_init(NULL);
>  arp_init();
>  domainfinalize(NULL);
> @@ -68,9 +85,13 @@ void net_init(void)
>  if_attachdomain(NULL);
>  vnet_loif_init();
>
> +/* Adding IPv4 address before starting the loopback interface
> + * cause the interface to be brought up without IPv6 support.
> + */
> +
>  /* Start the loopback device */
> -osv::start_if("lo0", "127.0.0.1", "255.0.0.0");
>  osv::ifup("lo0");
> +osv::start_if("lo0", "127.0.0.1", "255.0.0.0");
>
>  debug(" - done\n");
>  }
> diff --git a/bsd/porting/netport.h b/bsd/porting/netport.h
> index a433370..c797f25 100644
> --- a/bsd/porting/netport.h
> +++ b/bsd/porting/netport.h
> @@ -163,6 +163,10 @@ extern int tick;
>  #define INET (1)
>  #endif
>
> +#if defined(CONF_INET6) && (CONF_INET6 != 0)
> +#define INET6 (1)
> +#endif
> +
>  #ifdef _KERNEL
>
>  #define panic(...) do { tprintf_e("bsd-panic", __VA_ARGS__); \
> diff --git a/bsd/sys/dev/xen/netfront/netfront.cc
> b/bsd/sys/dev/xen/netfront/netfront.cc
> index c2b40ac..c4b40ba 100644
> --- a/bsd/sys/dev/xen/netfront/netfront.cc
> +++ b/bsd/sys/dev/xen/netfront/netfront.cc
> @@ -61,6 +61,10 @@ __FBSDID("$FreeBSD$");
>  #include 
>  #include 
>  #include 
> +#ifdef INET6
> +#include 
> +#include 
> +#endif
>  #include 
>  #if __FreeBSD_version >= 70
>  #include 
> diff --git a/conf/base.mk b/conf/base.mk
> index dcf98cd..54cd163 100644
> --- a/conf/base.mk
> +++ b/conf/base.mk
> @@ -9,3 +9,8 @@ conf-logger_debug=0
>  # This macro controls the NDEBUG macro that is used to identify the debug
>  # build variant in the code.
>  conf-DEBUG_BUILD=0
> +
> +# Set to 1 to enable IPV6
> +# This macro controls the FreeBSD INET6 macro defined in
> bsd/porting/netport.h
> +conf-INET6=1
> +
> diff --git 

[PATCH 16/16] bsd: Added conf-INET6 option to enable IPv6 support

2018-08-06 Thread Charles Myers
Signed-off-by: Charles Myers 
---
 Makefile | 27 ++-
 bsd/net.cc   | 23 +++-
 bsd/porting/netport.h|  4 +++
 bsd/sys/dev/xen/netfront/netfront.cc |  4 +++
 conf/base.mk |  5 
 include/api/netinet/in.h | 52 +++-
 6 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/Makefile b/Makefile
index d5b6fda..317e727 100644
--- a/Makefile
+++ b/Makefile
@@ -347,7 +347,7 @@ $(out)/bsd/%.o: INCLUDES += -isystem bsd/
 # for machine/
 $(out)/bsd/%.o: INCLUDES += -isystem bsd/$(arch)
 
-configuration-defines = conf-preempt conf-debug_memory conf-logger_debug
+configuration-defines = conf-preempt conf-debug_memory conf-logger_debug 
conf-INET6
 
 configuration = $(foreach cf,$(configuration-defines), \
   -D$(cf:conf-%=CONF_%)=$($(cf)))
@@ -611,6 +611,31 @@ bsd += bsd/sys/netinet/cc/cc_cubic.o
 bsd += bsd/sys/netinet/cc/cc_htcp.o
 bsd += bsd/sys/netinet/cc/cc_newreno.o
 bsd += bsd/sys/netinet/arpcache.o
+ifeq ($(conf-INET6), 1)
+bsd += bsd/sys/netinet6/dest6.o
+bsd += bsd/sys/netinet6/frag6.o
+bsd += bsd/sys/netinet6/icmp6.o
+bsd += bsd/sys/netinet6/in6.o
+bsd += bsd/sys/netinet6/in6_cksum.o
+bsd += bsd/sys/netinet6/in6_ifattach.o
+bsd += bsd/sys/netinet6/in6_mcast.o
+bsd += bsd/sys/netinet6/in6_pcb.o
+bsd += bsd/sys/netinet6/in6_proto.o
+bsd += bsd/sys/netinet6/in6_rmx.o
+bsd += bsd/sys/netinet6/in6_src.o
+bsd += bsd/sys/netinet6/ip6_forward.o
+bsd += bsd/sys/netinet6/ip6_id.o
+bsd += bsd/sys/netinet6/ip6_input.o
+bsd += bsd/sys/netinet6/ip6_output.o
+bsd += bsd/sys/netinet6/mld6.o
+bsd += bsd/sys/netinet6/nd6.o
+bsd += bsd/sys/netinet6/nd6_nbr.o
+bsd += bsd/sys/netinet6/nd6_rtr.o
+bsd += bsd/sys/netinet6/raw_ip6.o
+bsd += bsd/sys/netinet6/route6.o
+bsd += bsd/sys/netinet6/scope6.o
+bsd += bsd/sys/netinet6/udp6_usrreq.o
+endif
 bsd += bsd/sys/xdr/xdr.o
 bsd += bsd/sys/xdr/xdr_array.o
 bsd += bsd/sys/xdr/xdr_mem.o
diff --git a/bsd/net.cc b/bsd/net.cc
index f548e09..3fe334a 100644
--- a/bsd/net.cc
+++ b/bsd/net.cc
@@ -24,6 +24,11 @@
 #include 
 #include 
 #include 
+#ifdef INET6
+#include 
+#include 
+#include 
+#endif
 
 /* Generation of ip ids */
 void ip_initid(void);
@@ -31,6 +36,10 @@ void ip_initid(void);
 extern "C" {
 /* AF_INET */
 extern  struct domain inetdomain;
+#ifdef INET6
+/* AF_INET6 */
+extern  struct domain inet6domain;
+#endif
 /* AF_ROUTE */
 extern  struct domain routedomain;
 /* AF_NETLINK */
@@ -55,12 +64,20 @@ void net_init(void)
 vnet_pfil_init();
 domaininit(NULL);
 OSV_DOMAIN_SET(inet);
+#ifdef INET6
+OSV_DOMAIN_SET(inet6);
+#endif
 OSV_DOMAIN_SET(route);
 OSV_DOMAIN_SET(netlink);
 rts_init();
 route_init();
 vnet_route_init();
 netlink_init();
+#ifdef INET6
+ip6_init2(NULL);
+mld_init(NULL);
+vnet_mld_init(NULL);
+#endif
 ipport_tick_init(NULL);
 arp_init();
 domainfinalize(NULL);
@@ -68,9 +85,13 @@ void net_init(void)
 if_attachdomain(NULL);
 vnet_loif_init();
 
+/* Adding IPv4 address before starting the loopback interface
+ * cause the interface to be brought up without IPv6 support.
+ */
+
 /* Start the loopback device */
-osv::start_if("lo0", "127.0.0.1", "255.0.0.0");
 osv::ifup("lo0");
+osv::start_if("lo0", "127.0.0.1", "255.0.0.0");
 
 debug(" - done\n");
 }
diff --git a/bsd/porting/netport.h b/bsd/porting/netport.h
index a433370..c797f25 100644
--- a/bsd/porting/netport.h
+++ b/bsd/porting/netport.h
@@ -163,6 +163,10 @@ extern int tick;
 #define INET (1)
 #endif
 
+#if defined(CONF_INET6) && (CONF_INET6 != 0)
+#define INET6 (1)
+#endif
+
 #ifdef _KERNEL
 
 #define panic(...) do { tprintf_e("bsd-panic", __VA_ARGS__); \
diff --git a/bsd/sys/dev/xen/netfront/netfront.cc 
b/bsd/sys/dev/xen/netfront/netfront.cc
index c2b40ac..c4b40ba 100644
--- a/bsd/sys/dev/xen/netfront/netfront.cc
+++ b/bsd/sys/dev/xen/netfront/netfront.cc
@@ -61,6 +61,10 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#ifdef INET6
+#include 
+#include 
+#endif
 #include 
 #if __FreeBSD_version >= 70
 #include 
diff --git a/conf/base.mk b/conf/base.mk
index dcf98cd..54cd163 100644
--- a/conf/base.mk
+++ b/conf/base.mk
@@ -9,3 +9,8 @@ conf-logger_debug=0
 # This macro controls the NDEBUG macro that is used to identify the debug
 # build variant in the code.
 conf-DEBUG_BUILD=0
+
+# Set to 1 to enable IPV6
+# This macro controls the FreeBSD INET6 macro defined in bsd/porting/netport.h
+conf-INET6=1
+
diff --git a/include/api/netinet/in.h b/include/api/netinet/in.h
index 18fa77f..1b6d3f3 100644
--- a/include/api/netinet/in.h
+++ b/include/api/netinet/in.h
@@ -157,62 +157,16 @@ struct ip6_mtuinfo
uint32_t ip6m_mtu;
 };
 
-#define IPV6_ADDRFORM   1
-#define IPV6_2292PKTINFO2
-#define IPV6_2292HOPOPTS3
-#define IPV6_2292DSTOPTS4
-#define