kill command with IPv6 client address and port
PATCH 1/1 kill command with IPv6 client address and port
Hi
For ticket #280, this patch allows server to kill client with specified IPv6(port)And show port in status command
For example, when server started with proto udp6, the result of status 2 command shows like:CLIENT_LIST,admin,::ffff:192.168.25.147(1194),10.8.0.6,7849, ...CLIENT_LIST,admin,fe80::211:32ff:fe19:699b(1194),10.8.0.10,13010, ... And can kill client with kill command:kill ::ffff:192.168.25.147(1194)kill fe80::211:32ff:fe19:699b(1194)
--Roy
From 21db9f0c0dc80c9e71b80655a703123f12b9b46c Mon Sep 17 00:00:00 2001
From: roychang <[email protected]>
Date: Tue, 2 Sep 2014 19:03:01 +0800
Subject: <VPN Server> #227 - Support kill command for IPv6 client
- Add port info of IPv6 client in status command
Reviewer: benchang
--- src/openvpn/manage.c | 43 +++++++++++++++++++++++++++++++++++++++++-- src/openvpn/manage.h | 1 + src/openvpn/mroute.c | 10 ++++++++++ src/openvpn/multi.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-)
src/openvpn/manage.c +41 -2
@@ -454,18 +454,57 @@ man_kill (struct management *man, const char *victim) {struct gc_arena gc =gc_new (); -if (man->persist.callback.kill_by_cn && man->persist.callback.kill_by_addr) +if (man->persist.callback.kill_by_cn && man->persist.callback.kill_by_addr && man->persist.callback.kill_by_addr6) {struct buffer buf;char p1[128 ];char p2[128 ]; +char p3[128 ]; +char p4[128 ];int n_killed;buf_set_read (&buf, (uint8_t *) victim,strlen (victim) +1 );buf_parse (&buf,':' , p1,sizeof (p1));buf_parse (&buf,':' , p2,sizeof (p2)); -if (strlen (p1) &&strlen (p2)) +buf_set_read (&buf, (uint8_t *) victim,strlen (victim) +1 ); +buf_parse (&buf,'(' , p3,sizeof (p3)); +buf_parse (&buf,')' , p4,sizeof (p4)); + +if (strlen (p3) &&strlen (p4)) + { +/* IPv6(port) specified */ +int s; +struct in6_addr addr; + + s =inet_pton (AF_INET6 , p3, &addr); +if (s >0 ) + { +const int port =atoi (p4); +if (port >0 && port <65536 ) + { + n_killed = (*man->persist.callback.kill_by_addr6) (man->persist.callback.arg, addr, port); +if (n_killed >0 ) + { +msg (M_CLIENT ,"SUCCESS: %d client(s) at address %s:%d killed" , + n_killed, +print_in6_addr (addr,0 , &gc), + port); + } +else + { +msg (M_CLIENT ,"ERROR: client at address %s:%d not found" , +print_in6_addr (addr,0 , &gc), + port); + } + } + } +else + { +msg (M_CLIENT ,"ERROR: error parsing IPv6 address: %s" , p3); + } + } +else if (strlen (p1) &&strlen (p2)) {/* IP:port specified */ bool status;
src/openvpn/manage.h +1 -0
@@ -153,6 +153,7 @@ struct management_callbackvoid (*show_net) (void *arg,const int msglevel);int (*kill_by_cn) (void *arg,const char *common_name);int (*kill_by_addr) (void *arg,const in_addr_t addr,const int port); +int (*kill_by_addr6) (void *arg,const struct in6_addr addr,const int port);void (*delete_event) (void *arg,event_t event);int (*n_clients) (void *arg);#ifdef MANAGEMENT_DEF_AUTH
src/openvpn/mroute.c +10 -0
@@ -426,12 +426,22 @@ mroute_addr_print_ex (const struct mroute_addr *ma,break ;case MR_ADDR_IPV6 : { +struct buffer buf; +int port; +buf_set_read (&buf, maddr.addr, maddr.len); +buf_read_alloc (&buf,16 );buf_printf (&out,"%s" ,print_in6_addr ( *(struct in6_addr *)&maddr.addr,0 , gc));if (maddr.type &MR_WITH_NETBITS ) {buf_printf (&out,"/%d" , maddr.netbits); } +if (maddr.type &MR_WITH_PORT ) + { + port =buf_read_u16 (&buf); +if (port >=0 ) +buf_printf (&out,"(%d)" , port); + } }break ;default :
src/openvpn/multi.c +32 -0
@@ -2699,6 +2699,37 @@ management_callback_kill_by_addr (void *arg, const in_addr_t addr, const int porreturn count; } +static int +management_callback_kill_by_addr6 (void *arg,const struct in6_addr addr,const int port) +{ +struct multi_context *m = (struct multi_context *) arg; +struct hash_iterator hi; +struct hash_element *he; +struct openvpn_sockaddr saddr; +struct mroute_addr maddr; +int count =0 ; + +CLEAR (saddr); + saddr.addr.in6.sin6_family =AF_INET6 ; + saddr.addr.in6.sin6_addr = addr; + saddr.addr.in6.sin6_port =htons (port); +if (mroute_extract_openvpn_sockaddr (&maddr, &saddr, true)) + { +hash_iterator_init (m->iter, &hi); +while ((he =hash_iterator_next (&hi))) + { +struct multi_instance *mi = (struct multi_instance *) he->value; +if (!mi->halt &&mroute_addr_equal (&maddr, &mi->real)) + { +multi_signal_instance (m, mi,SIGTERM ); + ++count; + } + } +hash_iterator_free (&hi); + } +return count; +} +static void management_delete_event (void *arg,event_t event) {
@@ -2830,6 +2861,7 @@ init_management_callback_multi (struct multi_context *m) cb.show_net = management_show_net_callback; cb.kill_by_cn = management_callback_kill_by_cn; cb.kill_by_addr = management_callback_kill_by_addr; + cb.kill_by_addr6 = management_callback_kill_by_addr6; cb.delete_event = management_delete_event; cb.n_clients = management_callback_n_clients;#ifdef MANAGEMENT_DEF_AUTH
Signature · 1 line
1.7.9.5
Hi
For ticket #280, this patch allows server to kill client with specified IPv6(port) And show port in status command
For example, when server started with proto udp6, the result of status 2 command shows like:
CLIENT_LIST,admin,::ffff:192.168.25.147(1194),10.8.0.6,7849, ... CLIENT_LIST,admin,fe80::211:32ff:fe19:699b(1194),10.8.0.10,13010, ...
And can kill client with kill command:
kill ::ffff:192.168.25.147(1194)
kill fe80::211:32ff:fe19:699b(1194)
--
Roy
Hi,
Quoted 3 lines · On Wed, Sep 03, 2014 at 07:18:56PM +0800, ?i ?@?N wrote:
For ticket #280, this patch allows server to kill client with specified IPv6(port)And show port in status command
For example, when server started with proto udp6, the result of status 2 command shows like:CLIENT_LIST,admin,::ffff:192.168.25.147(1194),10.8.0.6,7849, ...CLIENT_LIST,admin,fe80::211:32ff:fe19:699b(1194),10.8.0.10,13010, ... And can kill client with kill command:kill ::ffff:192.168.25.147(1194)kill fe80::211:32ff:fe19:699b(1194)
Thanks.
While I opened that bug, I (still) wonder whether this functionality is really needed - we can always kill clients by client ID, no matter what protocol the client uses to connect... so maybe just add that fact to the documentation for the management interface...
Also, NAK on changing the format of "status 2" output. This will break applications that use the management interface - what you can do is add extra columns with a header, but not modify existing columns.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Hi Gert,
Thanks for your reply, it's my mistake
Now my question is how to record the client id every time when a client connected Is there a hook in server which will be triggered when a new client connect?
Currently in my application, I parse the result of status 2 to get the IP:port for killing But the client id is not a part of status 2 result
Is there a better way to do this?
Thanks again!
--
Roy
Am 03.09.14 22:36, schrieb 張 世杰:
Quoted 10 lines
Hi Gert,
Thanks for your reply, it's my mistake
Now my question is how to record the client id every time when a client connected Is there a hook in server which will be triggered when a new client connect?Currently in my application, I parse the result of status 2 to get the IP:port for killing But the client id is not a part of status 2 result
Is there a better way to do this?
Newer OpenVPN versions (I don't recall if -master or 2.3.x) have this information in the status report. For older version you have to record the ID when a client is connected.
Arne
Hi,
Quoted 3 lines · Arne Schwabe
Newer OpenVPN versions (I don't recall if -master or 2.3.x) have this information in the status report. For older version you have to record the ID when a client is connected.
In master:
commit 662ce6acc065bddf6490b3494725b8b3987b7def
Author: Arne Schwabe <[email protected]...> Date: Fri Aug 31 16:19:13 2012 +0200
Add the client id (CID) to the output of the status command
Wasn't backported to 2.3, due to "it's new functionality that might break existing usage".
In the context of this mail thread, this is slightly moot, though, as the new "kill by ip+port" patch would not get applied to 2.3 anyway (same reason), so use master and enjoy :-)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...