diff mbox series

[1/2] mini-os: netfront: retrieve netmask and gateway via extra function

Message ID 20200922105826.26274-2-jgross@suse.com (mailing list archive)
State New, archived
Headers show
Series mini-os: netfront: fix some issues | expand

Commit Message

Jürgen Groß Sept. 22, 2020, 10:58 a.m. UTC
Commit 1b8ed31f4ce40 ("mini-os: netfront: Read netmask and gateway from
Xenstore") modified init_netfront() to take two additional parameters.
This broke the Xen build as init_netfront() is used in grub stubdom,
too.

So instead of tightly coupling Mini-OS and Xen build via this interface
modification undo this change of init_netfront() and add two other
functions for retrieving the netmask and gateway for a network device.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/netfront.h |  4 +++-
 lwip-net.c         |  4 +++-
 netfront.c         | 21 +++++++++++++++------
 test.c             |  2 +-
 4 files changed, 22 insertions(+), 9 deletions(-)

Comments

Samuel Thibault Sept. 22, 2020, 8:08 p.m. UTC | #1
Juergen Gross, le mar. 22 sept. 2020 12:58:25 +0200, a ecrit:
> Commit 1b8ed31f4ce40 ("mini-os: netfront: Read netmask and gateway from
> Xenstore") modified init_netfront() to take two additional parameters.
> This broke the Xen build as init_netfront() is used in grub stubdom,
> too.
> 
> So instead of tightly coupling Mini-OS and Xen build via this interface
> modification undo this change of init_netfront() and add two other
> functions for retrieving the netmask and gateway for a network device.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/netfront.h |  4 +++-
>  lwip-net.c         |  4 +++-
>  netfront.c         | 21 +++++++++++++++------
>  test.c             |  2 +-
>  4 files changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/include/netfront.h b/include/netfront.h
> index bc3080e..ec641c8 100644
> --- a/include/netfront.h
> +++ b/include/netfront.h
> @@ -7,7 +7,9 @@ struct netfront_dev *init_netfront(char *nodename,
>                                     void (*netif_rx)(unsigned char *data,
>                                                      int len, void* arg),
>                                     unsigned char rawmac[6],
> -                                   char **ip, char **mask, char **gw);
> +                                   char **ip);
> +char *netfront_get_netmask(struct netfront_dev *dev);
> +char *netfront_get_gateway(struct netfront_dev *dev);
>  void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
>  void shutdown_netfront(struct netfront_dev *dev);
>  void suspend_netfront(void);
> diff --git a/lwip-net.c b/lwip-net.c
> index 80d1c8f..7e0d871 100644
> --- a/lwip-net.c
> +++ b/lwip-net.c
> @@ -347,7 +347,9 @@ void start_networking(void)
>  
>    tprintk("Waiting for network.\n");
>  
> -  dev = init_netfront(NULL, NULL, rawmac, &ip, &netmask_str, &gw_str);
> +  dev = init_netfront(NULL, NULL, rawmac, &ip);
> +  netmask_str = netfront_get_netmask(dev);
> +  gw_str = netfront_get_gateway(dev);
>    
>    if (ip) {
>      ipaddr.addr = inet_addr(ip);
> diff --git a/netfront.c b/netfront.c
> index 205484b..9057908 100644
> --- a/netfront.c
> +++ b/netfront.c
> @@ -65,6 +65,8 @@ struct netfront_dev {
>  
>      void (*netif_rx)(unsigned char* data, int len, void* arg);
>      void *netif_rx_arg;
> +
> +    struct netfront_dev_list *ldev;
>  };
>  
>  struct netfront_dev_list {
> @@ -303,7 +305,7 @@ struct netfront_dev *init_netfront(char *_nodename,
>                                     void (*thenetif_rx)(unsigned char* data,
>                                                         int len, void* arg),
>                                     unsigned char rawmac[6],
> -                                   char **ip, char **mask, char **gw)
> +                                   char **ip)
>  {
>      char nodename[256];
>      struct netfront_dev *dev;
> @@ -347,6 +349,7 @@ struct netfront_dev *init_netfront(char *_nodename,
>      memset(ldev, 0, sizeof(struct netfront_dev_list));
>  
>      if (_init_netfront(dev, ldev->rawmac, &(ldev->ip), &(ldev->mask), &(ldev->gw))) {
> +        dev->ldev = ldev;
>          ldev->dev = dev;
>          ldev->refcount = 1;
>          ldev->next = NULL;
> @@ -376,15 +379,21 @@ out:
>  	}
>      if (ip)
>          *ip = strdup(ldev->ip);
> -    if (mask)
> -        *mask = strdup(ldev->mask);
> -    if (gw)
> -        *gw = strdup(ldev->gw);
>  
>  err:
>      return dev;
>  }
>  
> +char *netfront_get_netmask(struct netfront_dev *dev)
> +{
> +    return dev->ldev->mask ? strdup(dev->ldev->mask) : NULL;
> +}
> +
> +char *netfront_get_gateway(struct netfront_dev *dev)
> +{
> +    return dev->ldev->gw ? strdup(dev->ldev->gw) : NULL;
> +}
> +
>  static struct netfront_dev *_init_netfront(struct netfront_dev *dev,
>  					   unsigned char rawmac[6],
>  					   char **ip, char **mask, char **gw)
> @@ -576,7 +585,7 @@ error:
>  int netfront_tap_open(char *nodename) {
>      struct netfront_dev *dev;
>  
> -    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL, NULL, NULL);
> +    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL);
>      if (!dev) {
>  	printk("TAP open failed\n");
>  	errno = EIO;
> diff --git a/test.c b/test.c
> index 2e5f7f9..42a2666 100644
> --- a/test.c
> +++ b/test.c
> @@ -91,7 +91,7 @@ static struct semaphore net_sem = __SEMAPHORE_INITIALIZER(net_sem, 0);
>  
>  static void netfront_thread(void *p)
>  {
> -    net_dev = init_netfront(NULL, NULL, NULL, NULL, NULL, NULL);
> +    net_dev = init_netfront(NULL, NULL, NULL, NULL);
>      up(&net_sem);
>  }
>  #endif
> -- 
> 2.26.2
>
diff mbox series

Patch

diff --git a/include/netfront.h b/include/netfront.h
index bc3080e..ec641c8 100644
--- a/include/netfront.h
+++ b/include/netfront.h
@@ -7,7 +7,9 @@  struct netfront_dev *init_netfront(char *nodename,
                                    void (*netif_rx)(unsigned char *data,
                                                     int len, void* arg),
                                    unsigned char rawmac[6],
-                                   char **ip, char **mask, char **gw);
+                                   char **ip);
+char *netfront_get_netmask(struct netfront_dev *dev);
+char *netfront_get_gateway(struct netfront_dev *dev);
 void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
 void shutdown_netfront(struct netfront_dev *dev);
 void suspend_netfront(void);
diff --git a/lwip-net.c b/lwip-net.c
index 80d1c8f..7e0d871 100644
--- a/lwip-net.c
+++ b/lwip-net.c
@@ -347,7 +347,9 @@  void start_networking(void)
 
   tprintk("Waiting for network.\n");
 
-  dev = init_netfront(NULL, NULL, rawmac, &ip, &netmask_str, &gw_str);
+  dev = init_netfront(NULL, NULL, rawmac, &ip);
+  netmask_str = netfront_get_netmask(dev);
+  gw_str = netfront_get_gateway(dev);
   
   if (ip) {
     ipaddr.addr = inet_addr(ip);
diff --git a/netfront.c b/netfront.c
index 205484b..9057908 100644
--- a/netfront.c
+++ b/netfront.c
@@ -65,6 +65,8 @@  struct netfront_dev {
 
     void (*netif_rx)(unsigned char* data, int len, void* arg);
     void *netif_rx_arg;
+
+    struct netfront_dev_list *ldev;
 };
 
 struct netfront_dev_list {
@@ -303,7 +305,7 @@  struct netfront_dev *init_netfront(char *_nodename,
                                    void (*thenetif_rx)(unsigned char* data,
                                                        int len, void* arg),
                                    unsigned char rawmac[6],
-                                   char **ip, char **mask, char **gw)
+                                   char **ip)
 {
     char nodename[256];
     struct netfront_dev *dev;
@@ -347,6 +349,7 @@  struct netfront_dev *init_netfront(char *_nodename,
     memset(ldev, 0, sizeof(struct netfront_dev_list));
 
     if (_init_netfront(dev, ldev->rawmac, &(ldev->ip), &(ldev->mask), &(ldev->gw))) {
+        dev->ldev = ldev;
         ldev->dev = dev;
         ldev->refcount = 1;
         ldev->next = NULL;
@@ -376,15 +379,21 @@  out:
 	}
     if (ip)
         *ip = strdup(ldev->ip);
-    if (mask)
-        *mask = strdup(ldev->mask);
-    if (gw)
-        *gw = strdup(ldev->gw);
 
 err:
     return dev;
 }
 
+char *netfront_get_netmask(struct netfront_dev *dev)
+{
+    return dev->ldev->mask ? strdup(dev->ldev->mask) : NULL;
+}
+
+char *netfront_get_gateway(struct netfront_dev *dev)
+{
+    return dev->ldev->gw ? strdup(dev->ldev->gw) : NULL;
+}
+
 static struct netfront_dev *_init_netfront(struct netfront_dev *dev,
 					   unsigned char rawmac[6],
 					   char **ip, char **mask, char **gw)
@@ -576,7 +585,7 @@  error:
 int netfront_tap_open(char *nodename) {
     struct netfront_dev *dev;
 
-    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL, NULL, NULL);
+    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL);
     if (!dev) {
 	printk("TAP open failed\n");
 	errno = EIO;
diff --git a/test.c b/test.c
index 2e5f7f9..42a2666 100644
--- a/test.c
+++ b/test.c
@@ -91,7 +91,7 @@  static struct semaphore net_sem = __SEMAPHORE_INITIALIZER(net_sem, 0);
 
 static void netfront_thread(void *p)
 {
-    net_dev = init_netfront(NULL, NULL, NULL, NULL, NULL, NULL);
+    net_dev = init_netfront(NULL, NULL, NULL, NULL);
     up(&net_sem);
 }
 #endif