Change in openvpn[master]: Bind to multiple ipv4/ipv6 addresses
A message that is not in the archive (sent off-list or not yet received): gerrit.1700055887000.Ia122d5cdc42c2969eef6f32f438e30b52652721f@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/438?usp=email
to review the following change.
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen
sockets based on the specified "--local"
directives.
The main server loop has been updated
to handle both TCP and UDP connections.
The hash function has also been modified
to include the protocol during the
creation of new client instances.
---
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/options.c
M src/openvpn/options.h
13 files changed, 613 insertions(+), 116 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/38/438/1
src/openvpn/forward.c +246 -1
@@ -1760,7 +1760,7 @@if (c->options.shaper) {int overhead =datagram_overhead (c->c2.to_link_addr->dest.addr.sa.sa_family, - c->options.ce.proto); + ls->info.proto);shaper_wrote_bytes (&c->c2.shaper,BLEN (&c->c2.to_link) + overhead); }
@@ -2050,6 +2050,250 @@*/ void +io_wait_dowork_udp (struct context *c,struct multi_tcp *mtcp,const unsigned int flags) +{ +unsigned int socket =0 ; +unsigned int tuntap =0 ; +struct event_set_return esr[4 ]; + +/* These shifts all depend on EVENT_READ and EVENT_WRITE */ +static uintptr_t socket_shift =0 ;/* depends on SOCKET_READ and SOCKET_WRITE */ +static uintptr_t tun_shift =2 ;/* depends on TUN_READ and TUN_WRITE */ +static uintptr_t err_shift =4 ;/* depends on ES_ERROR */ +#ifdef ENABLE_MANAGEMENT +static uintptr_t management_shift =6 ;/* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */ +#endif +#ifdef ENABLE_ASYNC_PUSH +static int file_shift =FILE_SHIFT ; +#endif +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) +static int dco_shift =DCO_SHIFT ;/* Event from DCO linux kernel module */ +#endif +int i; + +/* +* Decide what kind of events we want to wait for. +*/ +/*c->c2.event_set = mtcp->es; */ +/*event_reset(mtcp->es); */ +/*event_reset(c->c2.event_set); */ + +/* +* On win32 we use the keyboard or an event object as a source +* of asynchronous signals. +*/ +if (flags &IOW_WAIT_SIGNAL ) + { +wait_signal (mtcp->es, (void *)err_shift); + } + +/* +* If outgoing data (for TCP/UDP port) pending, wait for ready-to-send +* status from TCP/UDP port. Otherwise, wait for incoming data on +* TUN/TAP device. +*/ +if (flags &IOW_TO_LINK ) + { +if (flags &IOW_SHAPER ) + { +/* +* If sending this packet would put us over our traffic shaping +* quota, don't send -- instead compute the delay we must wait +* until it will be OK to send the packet. +*/ +int delay =0 ; + +/* set traffic shaping delay in microseconds */ +if (c->options.shaper) + { + delay =max_int (delay,shaper_delay (&c->c2.shaper)); + } + +if (delay <1000 ) + { + socket |=EVENT_WRITE ; + } +else + { +shaper_soonest_event (&c->c2.timeval, delay); + } + } +else + { + socket |=EVENT_WRITE ; + } + } +else if (!((flags &IOW_FRAG ) &&TO_LINK_FRAG (c))) + { +if (flags &IOW_READ_TUN ) + { + tuntap |=EVENT_READ ; + } + } + +/* +* If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status +* from device. Otherwise, wait for incoming data on TCP/UDP port. +*/ +if (flags &IOW_TO_TUN ) + { + tuntap |=EVENT_WRITE ; + } +else + { +if (flags &IOW_READ_LINK ) + { + socket |=EVENT_READ ; + } + } + +/* +* outgoing bcast buffer waiting to be sent? +*/ +if (flags &IOW_MBUF ) + { + socket |=EVENT_WRITE ; + } + +/* +* Force wait on TUN input, even if also waiting on TCP/UDP output +*/ +if (flags &IOW_READ_TUN_FORCE ) + { + tuntap |=EVENT_READ ; + } + +#ifdef _WIN32 +if (tuntap_is_wintun (c->c1.tuntap)) + { +/* +* With wintun we are only interested in read event. Ring buffer is +* always ready for write, so we don't do wait. +*/ + tuntap =EVENT_READ ; + } +#endif + +/* +* Configure event wait based on socket, tuntap flags. +*/ +for (i =0 ; i < c->c1.link_sockets_num; i++) + { +socket_set (c->c2.link_sockets[i], mtcp->es, socket, + &c->c2.link_sockets[i]->ev_arg,NULL ); + } +tun_set (c->c1.tuntap, c->c2.event_set, tuntap, (void *)tun_shift,NULL ); +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) +if (socket &EVENT_READ && c->c2.did_open_tun) + { +dco_event_set (&c->c1.tuntap->dco, mtcp->es, (void *)&dco_shift); + } +#endif + +#ifdef ENABLE_MANAGEMENT +if (management) + { +management_socket_set (management, mtcp->es, (void *)management_shift,NULL ); + } +#endif + +#ifdef ENABLE_ASYNC_PUSH +/* arm inotify watcher */ +if (c->options.mode ==MODE_SERVER ) + { +event_ctl (mtcp->es, c->c2.inotify_fd,EVENT_READ , (void *)&file_shift); + } +#endif + +/* +* Possible scenarios: +* (1) tcp/udp port has data available to read +* (2) tcp/udp port is ready to accept more data to write +* (3) tun dev has data available to read +* (4) tun dev is ready to accept more data to write +* (5) we received a signal (handler sets signal_received) +* (6) timeout (tv) expired +*/ + + mtcp->event_set_status =ES_ERROR ; + +if (!c->sig->signal_received) + { +if (!(flags &IOW_CHECK_RESIDUAL ) || !sockets_read_residual (c)) + { +int status; + +#ifdef ENABLE_DEBUG +if (check_debug_level (D_EVENT_WAIT )) + { +show_wait_status (c); + } +#endif + +/* +* Wait for something to happen. +*/ + status =event_wait (mtcp->es, &c->c2.timeval, esr,SIZE (esr)); + +check_status (status,"event_wait" ,NULL ,NULL ); + +if (status >0 ) + { +int i; + mtcp->event_set_status =0 ; +for (i =0 ; i < status; ++i) + { +const struct event_set_return *e = &esr[i]; +uintptr_t shift; + +if (e->arg >=MULTI_N ) + { +struct event_arg *ev_arg = (struct event_arg *)e->arg; +if (ev_arg->type !=EVENT_ARG_LINK_SOCKET ) + { + mtcp->event_set_status =ES_ERROR ; +msg (D_LINK_ERRORS , +"io_work: non socket event delivered" ); +return ; + } + + shift = socket_shift; +/* mark socket so that the multi code knows where we +* have pending i/o */ + ev_arg->pending = true; + } +else + { + shift = (uintptr_t )e->arg; + } + + mtcp->event_set_status |= ((e->rwflags &3 ) << shift); + } + } +else if (status ==0 ) + { + mtcp->event_set_status =ES_TIMEOUT ; + } + } +else + { + mtcp->event_set_status =SOCKET_READ ; + } + } + +/* 'now' should always be a reasonably up-to-date timestamp */ +update_time (); + +/* set signal_received if a signal was received */ +if (mtcp->event_set_status &ES_ERROR ) + { +get_signal (&c->sig->signal_received); + } + +dmsg (D_EVENT_WAIT ,"I/O WAIT status=0x%04x" , mtcp->event_set_status); +} + +void io_wait_dowork (struct context *c,const unsigned int flags) {unsigned int socket =0 ;
@@ -2291,6 +2535,7 @@dmsg (D_EVENT_WAIT ,"I/O WAIT status=0x%04x" , c->c2.event_set_status); } +void process_io (struct context *c,struct link_socket *ls) {
src/openvpn/forward.h +55 -0
73 lines not on this page · raw message
src/openvpn/init.c +41 -17
107 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +6 -1
@@ -76,6 +76,7 @@uint8_t len;/* length of address */ uint8_t unused;uint8_t type;/* MR_ADDR/MR_WITH flags */ +uint8_t proto;uint8_t netbits;/* number of bits in network part of address, * valid if MR_WITH_NETBITS is set */ union {
@@ -211,6 +212,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -232,7 +237,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +51 -30
148 lines not on this page · raw message
src/openvpn/mtcp.h +23 -0
@@ -31,6 +31,21 @@#include "event.h" /* +* TCP States +*/ +#define TA_UNDEF 0 +#define TA_SOCKET_READ 1 +#define TA_SOCKET_READ_RESIDUAL 2 +#define TA_SOCKET_WRITE 3 +#define TA_SOCKET_WRITE_READY 4 +#define TA_SOCKET_WRITE_DEFERRED 5 +#define TA_TUN_READ 6 +#define TA_TUN_WRITE 7 +#define TA_INITIAL 8 +#define TA_TIMEOUT 9 +#define TA_TUN_WRITE_TIMEOUT 10 + +/* * Extra state info needed for TCP mode */ struct multi_tcp
@@ -40,6 +55,7 @@int n_esr;int maxevents;unsigned int tun_rwflags; +unsigned int event_set_status;#ifdef ENABLE_MANAGEMENT unsigned int management_persist_flags;#endif
@@ -58,6 +74,13 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); +int multi_tcp_wait (struct context *c,struct multi_tcp *mtcp); + +void multi_tcp_process_io (struct multi_context *m); + +void multi_tcp_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll); + +void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi);
src/openvpn/mudp.c +58 -47
154 lines not on this page · raw message
src/openvpn/mudp.h +5 -1
@@ -31,6 +31,8 @@struct context ;struct multi_context ; +unsigned int +p2mp_iow_flags (const struct multi_context *m);/** * Main event loop for OpenVPN in UDP server mode.
@@ -40,9 +42,11 @@* * @param top - Top-level context structure. */ + +void tunnel_server_udp (struct context *top); - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +95 -15
153 lines not on this page · raw message
src/openvpn/multi.h +1 -1
@@ -262,7 +262,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/options.c +30 -3
@@ -2188,6 +2188,7 @@ } ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc); + e->proto =PROTO_NONE ; l->array[l->len++] = e;return e;
@@ -3154,14 +3155,30 @@if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_SERVER ; + o->ce.proto = ce->proto; + } +if (ce->local_list) + { +for (int i =0 ; i < ce->local_list->len; i++) + { +if (ce->local_list->array[i]->proto ==PROTO_TCP ) + { + ce->local_list->array[i]->proto =PROTO_TCP_SERVER ; + } +else if (ce->local_list->array[i]->proto ==PROTO_NONE ) + { + ce->local_list->array[i]->proto = ce->proto; + } + } } } -if (o->client) +if (o->mode !=MODE_SERVER ) {if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_CLIENT ; + o->ce.proto = ce->proto; } }
@@ -3312,6 +3329,10 @@ { le->port = o->ce.local_port; } +if (!le->proto) + { + le->proto = o->ce.proto; + } }#ifdef _WIN32
@@ -3775,6 +3796,7 @@ASSERT (e); e->port = o->ce.local_port; e->bind_local = o->ce.bind_local; + e->proto = o->ce.proto; }/* use the same listen list for every outgoing connection */
@@ -6164,7 +6186,7 @@VERIFY_PERMISSION (OPT_P_UP ); options->ifconfig_nowarn = true; } -else if (streq (p[0 ],"local" ) && p[1 ] && !p[3 ]) +else if (streq (p[0 ],"local" ) && p[1 ] && !p[4 ]) {struct local_entry *e;
@@ -6185,7 +6207,12 @@if (p[2 ]) { e->port = p[2 ]; - e->bind_local = true; +/*e->bind_local = true; */ + } + +if (p[3 ]) + { + e->proto =ascii2proto (p[3 ]); } }else if (streq (p[0 ],"remote-random" ) && !p[1 ])
src/openvpn/options.h +1 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/438?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia122d5cdc42c2969eef6f32f438e30b52652721f
Gerrit-Change-Number: 438
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/438?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/438?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia122d5cdc42c2969eef6f32f438e30b52652721f
Gerrit-Change-Number: 438
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon
ordex has restored this change. ( http://gerrit.openvpn.net/c/openvpn/+/438?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Restored
Signature · 13 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/438?usp=email To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ia122d5cdc42c2969eef6f32f438e30b52652721f Gerrit-Change-Number: 438 Gerrit-PatchSet: 1 Gerrit-Owner: ordex <[email protected]...> Gerrit-Reviewer: flichtenheld <[email protected]...> Gerrit-Reviewer: plaisthos <[email protected]...> Gerrit-CC: openvpn-devel <[email protected]> Gerrit-MessageType: restore
ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/438?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/438?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia122d5cdc42c2969eef6f32f438e30b52652721f
Gerrit-Change-Number: 438
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon