diff mbox series

[v3] net/slirp: libslirp 4.8.0 compatibility

Message ID 20250130114810.857224-1-mjt@tls.msk.ru (mailing list archive)
State New
Headers show
Series [v3] net/slirp: libslirp 4.8.0 compatibility | expand

Commit Message

Michael Tokarev Jan. 30, 2025, 11:48 a.m. UTC
Update the code in net/slirp.c to be compatible with
libslirp 4.8.0, which deprecated slirp_pollfds_fill()
and started using slirp_os_socket type for sockets
(which is a 64-bit integer on win64) for all callbacks
starting with version 6 of the interface.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
v2: update other callbacks too, use version 6 of the interface
v3: commit the changes before sending (*_sock => *_socket)

 net/slirp.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

Comments

Thomas Huth Jan. 30, 2025, 12:21 p.m. UTC | #1
On 30/01/2025 12.48, Michael Tokarev wrote:
> Update the code in net/slirp.c to be compatible with
> libslirp 4.8.0, which deprecated slirp_pollfds_fill()
> and started using slirp_os_socket type for sockets
> (which is a 64-bit integer on win64) for all callbacks
> starting with version 6 of the interface.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> v2: update other callbacks too, use version 6 of the interface
> v3: commit the changes before sending (*_sock => *_socket)
> 
>   net/slirp.c | 25 +++++++++++++++++--------
>   1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/net/slirp.c b/net/slirp.c
> index eb9a456ed4..2d2a58a6ee 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -247,7 +247,14 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer,
>       timer_mod(&t->timer, expire_timer);
>   }
>   
> -static void net_slirp_register_poll_fd(int fd, void *opaque)
> +#if !SLIRP_CHECK_VERSION(4,8,0)
> +# define slirp_os_socket int
> +# define slirp_pollfds_fill_socket slirp_pollfds_fill
> +# define register_poll_socket register_poll_fd

If I get that right, register_poll_socket has just been added to libslirp 
4.9.0, but is not available with 4.8.0 yet? ... so you might need to split 
the #if into two parts, one for 4.8.0 and one for 4.9.0 ?

  Thomas


> +# define unregister_poll_socket unregister_poll_fd
> +#endif
> +
> +static void net_slirp_register_poll_sock(slirp_os_socket fd, void *opaque)
>   {
>   #ifdef WIN32
>       AioContext *ctxt = qemu_get_aio_context();
> @@ -260,7 +267,7 @@ static void net_slirp_register_poll_fd(int fd, void *opaque)
>   #endif
>   }
>   
> -static void net_slirp_unregister_poll_fd(int fd, void *opaque)
> +static void net_slirp_unregister_poll_sock(slirp_os_socket fd, void *opaque)
>   {
>   #ifdef WIN32
>       if (WSAEventSelect(fd, NULL, 0) != 0) {
> @@ -286,8 +293,8 @@ static const SlirpCb slirp_cb = {
>   #endif
>       .timer_free = net_slirp_timer_free,
>       .timer_mod = net_slirp_timer_mod,
> -    .register_poll_fd = net_slirp_register_poll_fd,
> -    .unregister_poll_fd = net_slirp_unregister_poll_fd,
> +    .register_poll_socket = net_slirp_register_poll_sock,
> +    .unregister_poll_socket = net_slirp_unregister_poll_sock,
>       .notify = net_slirp_notify,
>   };
>   
> @@ -314,7 +321,7 @@ static int slirp_poll_to_gio(int events)
>       return ret;
>   }
>   
> -static int net_slirp_add_poll(int fd, int events, void *opaque)
> +static int net_slirp_add_poll(slirp_os_socket fd, int events, void *opaque)
>   {
>       GArray *pollfds = opaque;
>       GPollFD pfd = {
> @@ -363,8 +370,8 @@ static void net_slirp_poll_notify(Notifier *notifier, void *data)
>   
>       switch (poll->state) {
>       case MAIN_LOOP_POLL_FILL:
> -        slirp_pollfds_fill(s->slirp, &poll->timeout,
> -                           net_slirp_add_poll, poll->pollfds);
> +        slirp_pollfds_fill_socket(s->slirp, &poll->timeout,
> +                                  net_slirp_add_poll, poll->pollfds);
>           break;
>       case MAIN_LOOP_POLL_OK:
>       case MAIN_LOOP_POLL_ERR:
> @@ -629,7 +636,9 @@ static int net_slirp_init(NetClientState *peer, const char *model,
>   
>       s = DO_UPCAST(SlirpState, nc, nc);
>   
> -    cfg.version = SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
> +    cfg.version =
> +         SLIRP_CHECK_VERSION(4,8,0) ? 6 :
> +         SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
>       cfg.restricted = restricted;
>       cfg.in_enabled = ipv4;
>       cfg.vnetwork = net;
Michael Tokarev Jan. 30, 2025, 12:29 p.m. UTC | #2
30.01.2025 15:21, Thomas Huth wrote:
> On 30/01/2025 12.48, Michael Tokarev wrote:

>> +#if !SLIRP_CHECK_VERSION(4,8,0)
>> +# define slirp_os_socket int
>> +# define slirp_pollfds_fill_socket slirp_pollfds_fill
>> +# define register_poll_socket register_poll_fd
> 
> If I get that right, register_poll_socket has just been added to libslirp 4.9.0, but is not available with 4.8.0 yet? ... so you might need to split 
> the #if into two parts, one for 4.8.0 and one for 4.9.0 ?

Nope.  It all should be 4.9.0, not 4.8.0.  It is yet another result of
me doing things in ENOCOFFEE (or ETOOMUCHCOFFEE) mode today (I had
almost no sleep tonight due to other issues needing my attention).

I verified the code 4.7.x and the newly released 4.9.0, but not 4.8.x.
But it will fail with 4.8.x because the new fields aren't present there.

It should be SLIRP_CHECK_VERSION(4,9,0), that's all.

/mjt
Samuel Thibault Jan. 30, 2025, 12:31 p.m. UTC | #3
Thomas Huth, le jeu. 30 janv. 2025 13:21:23 +0100, a ecrit:
> On 30/01/2025 12.48, Michael Tokarev wrote:
> > Update the code in net/slirp.c to be compatible with
> > libslirp 4.8.0, which deprecated slirp_pollfds_fill()
> > and started using slirp_os_socket type for sockets
> > (which is a 64-bit integer on win64) for all callbacks
> > starting with version 6 of the interface.
> > 
> > Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> > ---
> > v2: update other callbacks too, use version 6 of the interface
> > v3: commit the changes before sending (*_sock => *_socket)
> > 
> >   net/slirp.c | 25 +++++++++++++++++--------
> >   1 file changed, 17 insertions(+), 8 deletions(-)
> > 
> > diff --git a/net/slirp.c b/net/slirp.c
> > index eb9a456ed4..2d2a58a6ee 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -247,7 +247,14 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer,
> >       timer_mod(&t->timer, expire_timer);
> >   }
> > -static void net_slirp_register_poll_fd(int fd, void *opaque)
> > +#if !SLIRP_CHECK_VERSION(4,8,0)

Shouldn't this be 4,9,0?

> > +# define slirp_os_socket int
> > +# define slirp_pollfds_fill_socket slirp_pollfds_fill
> > +# define register_poll_socket register_poll_fd
> 
> If I get that right, register_poll_socket has just been added to libslirp
> 4.9.0, but is not available with 4.8.0 yet?

Yes. None of these are defined in 4.8.0

> ... so you might need to split
> the #if into two parts, one for 4.8.0 and one for 4.9.0 ?

This is just defining what is in 4.9.0 but never before, so it should be
fine with just a ≥ 4.9.0 section.

Samuel

> > +# define unregister_poll_socket unregister_poll_fd
> > +#endif
> > +
> > +static void net_slirp_register_poll_sock(slirp_os_socket fd, void *opaque)
> >   {
> >   #ifdef WIN32
> >       AioContext *ctxt = qemu_get_aio_context();
> > @@ -260,7 +267,7 @@ static void net_slirp_register_poll_fd(int fd, void *opaque)
> >   #endif
> >   }
> > -static void net_slirp_unregister_poll_fd(int fd, void *opaque)
> > +static void net_slirp_unregister_poll_sock(slirp_os_socket fd, void *opaque)
> >   {
> >   #ifdef WIN32
> >       if (WSAEventSelect(fd, NULL, 0) != 0) {
> > @@ -286,8 +293,8 @@ static const SlirpCb slirp_cb = {
> >   #endif
> >       .timer_free = net_slirp_timer_free,
> >       .timer_mod = net_slirp_timer_mod,
> > -    .register_poll_fd = net_slirp_register_poll_fd,
> > -    .unregister_poll_fd = net_slirp_unregister_poll_fd,
> > +    .register_poll_socket = net_slirp_register_poll_sock,
> > +    .unregister_poll_socket = net_slirp_unregister_poll_sock,
> >       .notify = net_slirp_notify,
> >   };
> > @@ -314,7 +321,7 @@ static int slirp_poll_to_gio(int events)
> >       return ret;
> >   }
> > -static int net_slirp_add_poll(int fd, int events, void *opaque)
> > +static int net_slirp_add_poll(slirp_os_socket fd, int events, void *opaque)
> >   {
> >       GArray *pollfds = opaque;
> >       GPollFD pfd = {
> > @@ -363,8 +370,8 @@ static void net_slirp_poll_notify(Notifier *notifier, void *data)
> >       switch (poll->state) {
> >       case MAIN_LOOP_POLL_FILL:
> > -        slirp_pollfds_fill(s->slirp, &poll->timeout,
> > -                           net_slirp_add_poll, poll->pollfds);
> > +        slirp_pollfds_fill_socket(s->slirp, &poll->timeout,
> > +                                  net_slirp_add_poll, poll->pollfds);
> >           break;
> >       case MAIN_LOOP_POLL_OK:
> >       case MAIN_LOOP_POLL_ERR:
> > @@ -629,7 +636,9 @@ static int net_slirp_init(NetClientState *peer, const char *model,
> >       s = DO_UPCAST(SlirpState, nc, nc);
> > -    cfg.version = SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
> > +    cfg.version =
> > +         SLIRP_CHECK_VERSION(4,8,0) ? 6 :
> > +         SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
> >       cfg.restricted = restricted;
> >       cfg.in_enabled = ipv4;
> >       cfg.vnetwork = net;
>
diff mbox series

Patch

diff --git a/net/slirp.c b/net/slirp.c
index eb9a456ed4..2d2a58a6ee 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -247,7 +247,14 @@  static void net_slirp_timer_mod(void *timer, int64_t expire_timer,
     timer_mod(&t->timer, expire_timer);
 }
 
-static void net_slirp_register_poll_fd(int fd, void *opaque)
+#if !SLIRP_CHECK_VERSION(4,8,0)
+# define slirp_os_socket int
+# define slirp_pollfds_fill_socket slirp_pollfds_fill
+# define register_poll_socket register_poll_fd
+# define unregister_poll_socket unregister_poll_fd
+#endif
+
+static void net_slirp_register_poll_sock(slirp_os_socket fd, void *opaque)
 {
 #ifdef WIN32
     AioContext *ctxt = qemu_get_aio_context();
@@ -260,7 +267,7 @@  static void net_slirp_register_poll_fd(int fd, void *opaque)
 #endif
 }
 
-static void net_slirp_unregister_poll_fd(int fd, void *opaque)
+static void net_slirp_unregister_poll_sock(slirp_os_socket fd, void *opaque)
 {
 #ifdef WIN32
     if (WSAEventSelect(fd, NULL, 0) != 0) {
@@ -286,8 +293,8 @@  static const SlirpCb slirp_cb = {
 #endif
     .timer_free = net_slirp_timer_free,
     .timer_mod = net_slirp_timer_mod,
-    .register_poll_fd = net_slirp_register_poll_fd,
-    .unregister_poll_fd = net_slirp_unregister_poll_fd,
+    .register_poll_socket = net_slirp_register_poll_sock,
+    .unregister_poll_socket = net_slirp_unregister_poll_sock,
     .notify = net_slirp_notify,
 };
 
@@ -314,7 +321,7 @@  static int slirp_poll_to_gio(int events)
     return ret;
 }
 
-static int net_slirp_add_poll(int fd, int events, void *opaque)
+static int net_slirp_add_poll(slirp_os_socket fd, int events, void *opaque)
 {
     GArray *pollfds = opaque;
     GPollFD pfd = {
@@ -363,8 +370,8 @@  static void net_slirp_poll_notify(Notifier *notifier, void *data)
 
     switch (poll->state) {
     case MAIN_LOOP_POLL_FILL:
-        slirp_pollfds_fill(s->slirp, &poll->timeout,
-                           net_slirp_add_poll, poll->pollfds);
+        slirp_pollfds_fill_socket(s->slirp, &poll->timeout,
+                                  net_slirp_add_poll, poll->pollfds);
         break;
     case MAIN_LOOP_POLL_OK:
     case MAIN_LOOP_POLL_ERR:
@@ -629,7 +636,9 @@  static int net_slirp_init(NetClientState *peer, const char *model,
 
     s = DO_UPCAST(SlirpState, nc, nc);
 
-    cfg.version = SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
+    cfg.version =
+         SLIRP_CHECK_VERSION(4,8,0) ? 6 :
+         SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
     cfg.restricted = restricted;
     cfg.in_enabled = ipv4;
     cfg.vnetwork = net;