Explorar o código

ncd: modules: remove ip_in_network.c and make ip_in_network() an alias for net.ipv4.addr_in_network()

ambrop7 %!s(int64=13) %!d(string=hai) anos
pai
achega
1996f362b4

+ 0 - 1
blog_channels.txt

@@ -17,7 +17,6 @@ ncd_logical 4
 ncd_sleep 4
 ncd_sleep 4
 ncd_print 4
 ncd_print 4
 ncd_blocker 4
 ncd_blocker 4
-ncd_ip_in_network 4
 ncd_run 4
 ncd_run 4
 ncd_runonce 4
 ncd_runonce 4
 ncd_daemon 4
 ncd_daemon 4

+ 112 - 113
generated/blog_channels_defines.h

@@ -17,116 +17,115 @@
 #define BLOG_CHANNEL_ncd_sleep 16
 #define BLOG_CHANNEL_ncd_sleep 16
 #define BLOG_CHANNEL_ncd_print 17
 #define BLOG_CHANNEL_ncd_print 17
 #define BLOG_CHANNEL_ncd_blocker 18
 #define BLOG_CHANNEL_ncd_blocker 18
-#define BLOG_CHANNEL_ncd_ip_in_network 19
-#define BLOG_CHANNEL_ncd_run 20
-#define BLOG_CHANNEL_ncd_runonce 21
-#define BLOG_CHANNEL_ncd_daemon 22
-#define BLOG_CHANNEL_ncd_spawn 23
-#define BLOG_CHANNEL_ncd_call 24
-#define BLOG_CHANNEL_ncd_imperative 25
-#define BLOG_CHANNEL_ncd_ref 26
-#define BLOG_CHANNEL_ncd_index 27
-#define BLOG_CHANNEL_ncd_alias 28
-#define BLOG_CHANNEL_ncd_process_manager 29
-#define BLOG_CHANNEL_ncd_ondemand 30
-#define BLOG_CHANNEL_ncd_foreach 31
-#define BLOG_CHANNEL_ncd_choose 32
-#define BLOG_CHANNEL_ncd_net_backend_waitdevice 33
-#define BLOG_CHANNEL_ncd_net_backend_waitlink 34
-#define BLOG_CHANNEL_ncd_net_backend_badvpn 35
-#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 36
-#define BLOG_CHANNEL_ncd_net_backend_rfkill 37
-#define BLOG_CHANNEL_ncd_net_up 38
-#define BLOG_CHANNEL_ncd_net_dns 39
-#define BLOG_CHANNEL_ncd_net_iptables 40
-#define BLOG_CHANNEL_ncd_net_ipv4_addr 41
-#define BLOG_CHANNEL_ncd_net_ipv4_route 42
-#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 43
-#define BLOG_CHANNEL_ncd_net_ipv4_arp_probe 44
-#define BLOG_CHANNEL_ncd_net_watch_interfaces 45
-#define BLOG_CHANNEL_ncd_sys_watch_input 46
-#define BLOG_CHANNEL_ncd_sys_watch_usb 47
-#define BLOG_CHANNEL_ncd_sys_evdev 48
-#define BLOG_CHANNEL_ncd_sys_watch_directory 49
-#define BLOG_CHANNEL_StreamPeerIO 50
-#define BLOG_CHANNEL_DatagramPeerIO 51
-#define BLOG_CHANNEL_BReactor 52
-#define BLOG_CHANNEL_BSignal 53
-#define BLOG_CHANNEL_FragmentProtoAssembler 54
-#define BLOG_CHANNEL_BPredicate 55
-#define BLOG_CHANNEL_ServerConnection 56
-#define BLOG_CHANNEL_Listener 57
-#define BLOG_CHANNEL_DataProto 58
-#define BLOG_CHANNEL_FrameDecider 59
-#define BLOG_CHANNEL_BSocksClient 60
-#define BLOG_CHANNEL_BDHCPClientCore 61
-#define BLOG_CHANNEL_BDHCPClient 62
-#define BLOG_CHANNEL_NCDIfConfig 63
-#define BLOG_CHANNEL_BUnixSignal 64
-#define BLOG_CHANNEL_BProcess 65
-#define BLOG_CHANNEL_PRStreamSink 66
-#define BLOG_CHANNEL_PRStreamSource 67
-#define BLOG_CHANNEL_PacketProtoDecoder 68
-#define BLOG_CHANNEL_DPRelay 69
-#define BLOG_CHANNEL_BThreadWork 70
-#define BLOG_CHANNEL_DPReceive 71
-#define BLOG_CHANNEL_BInputProcess 72
-#define BLOG_CHANNEL_NCDUdevMonitorParser 73
-#define BLOG_CHANNEL_NCDUdevMonitor 74
-#define BLOG_CHANNEL_NCDUdevCache 75
-#define BLOG_CHANNEL_NCDUdevManager 76
-#define BLOG_CHANNEL_BTime 77
-#define BLOG_CHANNEL_BEncryption 78
-#define BLOG_CHANNEL_SPProtoDecoder 79
-#define BLOG_CHANNEL_LineBuffer 80
-#define BLOG_CHANNEL_BTap 81
-#define BLOG_CHANNEL_lwip 82
-#define BLOG_CHANNEL_NCDConfigTokenizer 83
-#define BLOG_CHANNEL_NCDConfigParser 84
-#define BLOG_CHANNEL_NCDValueParser 85
-#define BLOG_CHANNEL_nsskey 86
-#define BLOG_CHANNEL_addr 87
-#define BLOG_CHANNEL_PasswordListener 88
-#define BLOG_CHANNEL_NCDInterfaceMonitor 89
-#define BLOG_CHANNEL_NCDRfkillMonitor 90
-#define BLOG_CHANNEL_udpgw 91
-#define BLOG_CHANNEL_UdpGwClient 92
-#define BLOG_CHANNEL_SocksUdpGwClient 93
-#define BLOG_CHANNEL_BNetwork 94
-#define BLOG_CHANNEL_BConnection 95
-#define BLOG_CHANNEL_BSSLConnection 96
-#define BLOG_CHANNEL_BDatagram 97
-#define BLOG_CHANNEL_PeerChat 98
-#define BLOG_CHANNEL_BArpProbe 99
-#define BLOG_CHANNEL_NCDModuleIndex 100
-#define BLOG_CHANNEL_NCDModuleProcess 101
-#define BLOG_CHANNEL_NCDValueGenerator 102
-#define BLOG_CHANNEL_ncd_from_string 103
-#define BLOG_CHANNEL_ncd_to_string 104
-#define BLOG_CHANNEL_ncd_value 105
-#define BLOG_CHANNEL_ncd_try 106
-#define BLOG_CHANNEL_ncd_sys_request_server 107
-#define BLOG_CHANNEL_NCDRequest 108
-#define BLOG_CHANNEL_ncd_net_ipv6_wait_dynamic_addr 109
-#define BLOG_CHANNEL_NCDRequestClient 110
-#define BLOG_CHANNEL_ncd_request 111
-#define BLOG_CHANNEL_ncd_sys_request_client 112
-#define BLOG_CHANNEL_ncd_exit 113
-#define BLOG_CHANNEL_ncd_getargs 114
-#define BLOG_CHANNEL_ncd_arithmetic 115
-#define BLOG_CHANNEL_ncd_parse 116
-#define BLOG_CHANNEL_ncd_valuemetic 117
-#define BLOG_CHANNEL_ncd_file 118
-#define BLOG_CHANNEL_ncd_netmask 119
-#define BLOG_CHANNEL_ncd_implode 120
-#define BLOG_CHANNEL_ncd_call2 121
-#define BLOG_CHANNEL_ncd_assert 122
-#define BLOG_CHANNEL_ncd_reboot 123
-#define BLOG_CHANNEL_ncd_explode 124
-#define BLOG_CHANNEL_NCDPlaceholderDb 125
-#define BLOG_CHANNEL_NCDVal 126
-#define BLOG_CHANNEL_ncd_net_ipv6_addr 127
-#define BLOG_CHANNEL_ncd_net_ipv6_route 128
-#define BLOG_CHANNEL_ncd_net_ipv4_addr_in_network 129
-#define BLOG_CHANNEL_ncd_net_ipv6_addr_in_network 130
-#define BLOG_NUM_CHANNELS 131
+#define BLOG_CHANNEL_ncd_run 19
+#define BLOG_CHANNEL_ncd_runonce 20
+#define BLOG_CHANNEL_ncd_daemon 21
+#define BLOG_CHANNEL_ncd_spawn 22
+#define BLOG_CHANNEL_ncd_call 23
+#define BLOG_CHANNEL_ncd_imperative 24
+#define BLOG_CHANNEL_ncd_ref 25
+#define BLOG_CHANNEL_ncd_index 26
+#define BLOG_CHANNEL_ncd_alias 27
+#define BLOG_CHANNEL_ncd_process_manager 28
+#define BLOG_CHANNEL_ncd_ondemand 29
+#define BLOG_CHANNEL_ncd_foreach 30
+#define BLOG_CHANNEL_ncd_choose 31
+#define BLOG_CHANNEL_ncd_net_backend_waitdevice 32
+#define BLOG_CHANNEL_ncd_net_backend_waitlink 33
+#define BLOG_CHANNEL_ncd_net_backend_badvpn 34
+#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 35
+#define BLOG_CHANNEL_ncd_net_backend_rfkill 36
+#define BLOG_CHANNEL_ncd_net_up 37
+#define BLOG_CHANNEL_ncd_net_dns 38
+#define BLOG_CHANNEL_ncd_net_iptables 39
+#define BLOG_CHANNEL_ncd_net_ipv4_addr 40
+#define BLOG_CHANNEL_ncd_net_ipv4_route 41
+#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 42
+#define BLOG_CHANNEL_ncd_net_ipv4_arp_probe 43
+#define BLOG_CHANNEL_ncd_net_watch_interfaces 44
+#define BLOG_CHANNEL_ncd_sys_watch_input 45
+#define BLOG_CHANNEL_ncd_sys_watch_usb 46
+#define BLOG_CHANNEL_ncd_sys_evdev 47
+#define BLOG_CHANNEL_ncd_sys_watch_directory 48
+#define BLOG_CHANNEL_StreamPeerIO 49
+#define BLOG_CHANNEL_DatagramPeerIO 50
+#define BLOG_CHANNEL_BReactor 51
+#define BLOG_CHANNEL_BSignal 52
+#define BLOG_CHANNEL_FragmentProtoAssembler 53
+#define BLOG_CHANNEL_BPredicate 54
+#define BLOG_CHANNEL_ServerConnection 55
+#define BLOG_CHANNEL_Listener 56
+#define BLOG_CHANNEL_DataProto 57
+#define BLOG_CHANNEL_FrameDecider 58
+#define BLOG_CHANNEL_BSocksClient 59
+#define BLOG_CHANNEL_BDHCPClientCore 60
+#define BLOG_CHANNEL_BDHCPClient 61
+#define BLOG_CHANNEL_NCDIfConfig 62
+#define BLOG_CHANNEL_BUnixSignal 63
+#define BLOG_CHANNEL_BProcess 64
+#define BLOG_CHANNEL_PRStreamSink 65
+#define BLOG_CHANNEL_PRStreamSource 66
+#define BLOG_CHANNEL_PacketProtoDecoder 67
+#define BLOG_CHANNEL_DPRelay 68
+#define BLOG_CHANNEL_BThreadWork 69
+#define BLOG_CHANNEL_DPReceive 70
+#define BLOG_CHANNEL_BInputProcess 71
+#define BLOG_CHANNEL_NCDUdevMonitorParser 72
+#define BLOG_CHANNEL_NCDUdevMonitor 73
+#define BLOG_CHANNEL_NCDUdevCache 74
+#define BLOG_CHANNEL_NCDUdevManager 75
+#define BLOG_CHANNEL_BTime 76
+#define BLOG_CHANNEL_BEncryption 77
+#define BLOG_CHANNEL_SPProtoDecoder 78
+#define BLOG_CHANNEL_LineBuffer 79
+#define BLOG_CHANNEL_BTap 80
+#define BLOG_CHANNEL_lwip 81
+#define BLOG_CHANNEL_NCDConfigTokenizer 82
+#define BLOG_CHANNEL_NCDConfigParser 83
+#define BLOG_CHANNEL_NCDValueParser 84
+#define BLOG_CHANNEL_nsskey 85
+#define BLOG_CHANNEL_addr 86
+#define BLOG_CHANNEL_PasswordListener 87
+#define BLOG_CHANNEL_NCDInterfaceMonitor 88
+#define BLOG_CHANNEL_NCDRfkillMonitor 89
+#define BLOG_CHANNEL_udpgw 90
+#define BLOG_CHANNEL_UdpGwClient 91
+#define BLOG_CHANNEL_SocksUdpGwClient 92
+#define BLOG_CHANNEL_BNetwork 93
+#define BLOG_CHANNEL_BConnection 94
+#define BLOG_CHANNEL_BSSLConnection 95
+#define BLOG_CHANNEL_BDatagram 96
+#define BLOG_CHANNEL_PeerChat 97
+#define BLOG_CHANNEL_BArpProbe 98
+#define BLOG_CHANNEL_NCDModuleIndex 99
+#define BLOG_CHANNEL_NCDModuleProcess 100
+#define BLOG_CHANNEL_NCDValueGenerator 101
+#define BLOG_CHANNEL_ncd_from_string 102
+#define BLOG_CHANNEL_ncd_to_string 103
+#define BLOG_CHANNEL_ncd_value 104
+#define BLOG_CHANNEL_ncd_try 105
+#define BLOG_CHANNEL_ncd_sys_request_server 106
+#define BLOG_CHANNEL_NCDRequest 107
+#define BLOG_CHANNEL_ncd_net_ipv6_wait_dynamic_addr 108
+#define BLOG_CHANNEL_NCDRequestClient 109
+#define BLOG_CHANNEL_ncd_request 110
+#define BLOG_CHANNEL_ncd_sys_request_client 111
+#define BLOG_CHANNEL_ncd_exit 112
+#define BLOG_CHANNEL_ncd_getargs 113
+#define BLOG_CHANNEL_ncd_arithmetic 114
+#define BLOG_CHANNEL_ncd_parse 115
+#define BLOG_CHANNEL_ncd_valuemetic 116
+#define BLOG_CHANNEL_ncd_file 117
+#define BLOG_CHANNEL_ncd_netmask 118
+#define BLOG_CHANNEL_ncd_implode 119
+#define BLOG_CHANNEL_ncd_call2 120
+#define BLOG_CHANNEL_ncd_assert 121
+#define BLOG_CHANNEL_ncd_reboot 122
+#define BLOG_CHANNEL_ncd_explode 123
+#define BLOG_CHANNEL_NCDPlaceholderDb 124
+#define BLOG_CHANNEL_NCDVal 125
+#define BLOG_CHANNEL_ncd_net_ipv6_addr 126
+#define BLOG_CHANNEL_ncd_net_ipv6_route 127
+#define BLOG_CHANNEL_ncd_net_ipv4_addr_in_network 128
+#define BLOG_CHANNEL_ncd_net_ipv6_addr_in_network 129
+#define BLOG_NUM_CHANNELS 130

+ 0 - 1
generated/blog_channels_list.h

@@ -17,7 +17,6 @@
 {"ncd_sleep", 4},
 {"ncd_sleep", 4},
 {"ncd_print", 4},
 {"ncd_print", 4},
 {"ncd_blocker", 4},
 {"ncd_blocker", 4},
-{"ncd_ip_in_network", 4},
 {"ncd_run", 4},
 {"ncd_run", 4},
 {"ncd_runonce", 4},
 {"ncd_runonce", 4},
 {"ncd_daemon", 4},
 {"ncd_daemon", 4},

+ 0 - 1
ncd/CMakeLists.txt

@@ -102,7 +102,6 @@ add_executable(badvpn-ncd
     modules/sleep.c
     modules/sleep.c
     modules/print.c
     modules/print.c
     modules/blocker.c
     modules/blocker.c
-    modules/ip_in_network.c
     modules/run.c
     modules/run.c
     modules/runonce.c
     modules/runonce.c
     modules/daemon.c
     modules/daemon.c

+ 0 - 139
ncd/modules/ip_in_network.c

@@ -1,139 +0,0 @@
-/**
- * @file ip_in_network.c
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- * 
- * @section LICENSE
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the
- *    names of its contributors may be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- * @section DESCRIPTION
- * 
- * Module for checking whether two IP addresses belong to the same network.
- * 
- * Synopsis: ip_in_network(string addr1, string addr2, string netprefix)
- * Variables:
- *   string (empty) - "true" if addr1 and addr2 are in the same network, with
- *     netprefix prefix, "false" if not (IPv4 only).
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <misc/ipaddr.h>
-#include <ncd/NCDModule.h>
-
-#include <generated/blog_channel_ncd_ip_in_network.h>
-
-#define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
-
-struct instance {
-    NCDModuleInst *i;
-    int value;
-};
-
-static void func_new (void *vo, NCDModuleInst *i)
-{
-    struct instance *o = vo;
-    o->i = i;
-    
-    // read arguments
-    NCDValRef arg_addr1;
-    NCDValRef arg_addr2;
-    NCDValRef arg_netprefix;
-    if (!NCDVal_ListRead(o->i->args, 3, &arg_addr1, &arg_addr2, &arg_netprefix)) {
-        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
-        goto fail0;
-    }
-    if (!NCDVal_IsStringNoNulls(arg_addr1) || !NCDVal_IsStringNoNulls(arg_addr2) || !NCDVal_IsStringNoNulls(arg_netprefix)) {
-        ModuleLog(o->i, BLOG_ERROR, "wrong type");
-        goto fail0;
-    }
-    
-    // parse
-    uint32_t addr1;
-    uint32_t addr2;
-    int netprefix;
-    if (!ipaddr_parse_ipv4_addr((char *)NCDVal_StringValue(arg_addr1), &addr1)) {
-        ModuleLog(o->i, BLOG_ERROR, "wrong addr1");
-        goto fail0;
-    }
-    if (!ipaddr_parse_ipv4_addr((char *)NCDVal_StringValue(arg_addr2), &addr2)) {
-        ModuleLog(o->i, BLOG_ERROR, "wrong addr2");
-        goto fail0;
-    }
-    if (!ipaddr_parse_ipv4_prefix((char *)NCDVal_StringValue(arg_netprefix), &netprefix)) {
-        ModuleLog(o->i, BLOG_ERROR, "wrong netprefix");
-        goto fail0;
-    }
-    
-    // test
-    o->value = ipaddr_ipv4_addrs_in_network(addr1, addr2, netprefix);
-    
-    // signal up
-    NCDModuleInst_Backend_Up(o->i);
-    return;
-    
-fail0:
-    NCDModuleInst_Backend_SetError(i);
-    NCDModuleInst_Backend_Dead(i);
-}
-
-static void func_die (void *vo)
-{
-    struct instance *o = vo;
-    
-    NCDModuleInst_Backend_Dead(o->i);
-}
-
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
-{
-    struct instance *o = vo;
-    
-    if (!strcmp(name, "")) {
-        const char *v = (o->value ? "true" : "false");
-        
-        *out = NCDVal_NewString(mem, v);
-        if (NCDVal_IsInvalid(*out)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
-        }
-        return 1;
-    }
-    
-    return 0;
-}
-
-static const struct NCDModule modules[] = {
-    {
-        .type = "ip_in_network",
-        .func_new2 = func_new,
-        .func_die = func_die,
-        .func_getvar = func_getvar,
-        .alloc_size = sizeof(struct instance)
-    }, {
-        .type = NULL
-    }
-};
-
-const struct NCDModuleGroup ncdmodule_ip_in_network = {
-    .modules = modules
-};

+ 0 - 2
ncd/modules/modules.h

@@ -48,7 +48,6 @@ extern const struct NCDModuleGroup ncdmodule_logical;
 extern const struct NCDModuleGroup ncdmodule_sleep;
 extern const struct NCDModuleGroup ncdmodule_sleep;
 extern const struct NCDModuleGroup ncdmodule_print;
 extern const struct NCDModuleGroup ncdmodule_print;
 extern const struct NCDModuleGroup ncdmodule_blocker;
 extern const struct NCDModuleGroup ncdmodule_blocker;
-extern const struct NCDModuleGroup ncdmodule_ip_in_network;
 extern const struct NCDModuleGroup ncdmodule_run;
 extern const struct NCDModuleGroup ncdmodule_run;
 extern const struct NCDModuleGroup ncdmodule_runonce;
 extern const struct NCDModuleGroup ncdmodule_runonce;
 extern const struct NCDModuleGroup ncdmodule_daemon;
 extern const struct NCDModuleGroup ncdmodule_daemon;
@@ -124,7 +123,6 @@ static const struct NCDModuleGroup *ncd_modules[] = {
     &ncdmodule_sleep,
     &ncdmodule_sleep,
     &ncdmodule_print,
     &ncdmodule_print,
     &ncdmodule_blocker,
     &ncdmodule_blocker,
-    &ncdmodule_ip_in_network,
     &ncdmodule_run,
     &ncdmodule_run,
     &ncdmodule_runonce,
     &ncdmodule_runonce,
     &ncdmodule_daemon,
     &ncdmodule_daemon,

+ 5 - 0
ncd/modules/net_ipv4_addr_in_network.c

@@ -157,6 +157,11 @@ static const struct NCDModule modules[] = {
         .func_new2 = func_new_normal,
         .func_new2 = func_new_normal,
         .func_getvar = func_getvar,
         .func_getvar = func_getvar,
         .alloc_size = sizeof(struct instance)
         .alloc_size = sizeof(struct instance)
+    }, {
+        .type = "ip_in_network", // compatibility name
+        .func_new2 = func_new_normal,
+        .func_getvar = func_getvar,
+        .alloc_size = sizeof(struct instance)
     }, {
     }, {
         .type = "net.ipv4.ifnot_addr_in_network",
         .type = "net.ipv4.ifnot_addr_in_network",
         .func_new2 = func_new_ifnot,
         .func_new2 = func_new_ifnot,