]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
manage: Change kill_by_addr to use better types for port/proto
authorFrank Lichtenheld <frank@lichtenheld.com>
Thu, 30 Oct 2025 18:29:12 +0000 (19:29 +0100)
committerGert Doering <gert@greenie.muc.de>
Thu, 30 Oct 2025 18:41:11 +0000 (19:41 +0100)
Change-Id: I750a0b8107baa77fb14558d0c8e4ef8020d62efd
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1310
Message-Id: <20251030182922.26448-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34054.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/manage.c
src/openvpn/manage.h
src/openvpn/multi.c
src/openvpn/socket.h

index 685b137cfba103b8facc56fbe90ff4d43a42696c..e46b5f227ac15e94e6217357ac53a1b8c99ebe03 100644 (file)
@@ -608,14 +608,14 @@ man_kill(struct management *man, const char *victim)
             if (status)
             {
                 const int port = atoi(p3);
-                const int proto = (streq(p1, "tcp"))   ? PROTO_TCP_SERVER
-                                  : (streq(p1, "udp")) ? PROTO_UDP
-                                                       : PROTO_NONE;
+                const uint8_t proto = (streq(p1, "tcp"))   ? PROTO_TCP_SERVER
+                                      : (streq(p1, "udp")) ? PROTO_UDP
+                                                           : PROTO_NONE;
 
-                if ((port > 0 && port < 65536) && (proto != PROTO_NONE))
+                if ((port > 0 && port < UINT16_MAX) && (proto != PROTO_NONE))
                 {
                     n_killed = (*man->persist.callback.kill_by_addr)(man->persist.callback.arg,
-                                                                     addr, port, proto);
+                                                                     addr, (uint16_t)port, proto);
                     if (n_killed > 0)
                     {
                         msg(M_CLIENT, "SUCCESS: %d client(s) at address %s:%s:%d killed", n_killed,
index fe460bfbb9060f936374fdb34cf244d63f1fe35d..dedcc1558026b75faad5348438f67b19b1489e37 100644 (file)
@@ -178,7 +178,7 @@ struct management_callback
     void (*status)(void *arg, const int version, struct status_output *so);
     void (*show_net)(void *arg, const msglvl_t 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, const int proto);
+    int (*kill_by_addr)(void *arg, const in_addr_t addr, const uint16_t port, const uint8_t proto);
     void (*delete_event)(void *arg, event_t event);
     int (*n_clients)(void *arg);
     bool (*send_cc_message)(void *arg, const char *message, const char *parameter);
index e2438432f811c246e0266cc9ab2d649f356ffedf..261209d0ec703cea4fef6d436db1400ba9105a15 100644 (file)
@@ -3937,7 +3937,7 @@ management_callback_kill_by_cn(void *arg, const char *del_cn)
 }
 
 static int
-management_callback_kill_by_addr(void *arg, const in_addr_t addr, const int port, const int proto)
+management_callback_kill_by_addr(void *arg, const in_addr_t addr, const uint16_t port, const uint8_t proto)
 {
     struct multi_context *m = (struct multi_context *)arg;
     struct hash_iterator hi;
index e986c9cf793235b6ec69eb90f516617d7a5472fa..832d62e2ad2b18f9de28a3af42ca402322c52dde 100644 (file)
@@ -89,7 +89,7 @@ struct link_socket_info
     const char *ipchange_command;
     const struct plugin_list *plugins;
     bool remote_float;
-    int proto;       /* Protocol (PROTO_x defined below) */
+    uint8_t proto;   /* Protocol (PROTO_x defined below) */
     sa_family_t af;  /* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/
     bool bind_ipv6_only;
     int mtu_changed; /* Set to true when mtu value is changed */