Module: kamailio Branch: master Commit: a10e7652f24bc7ed8e74ff27d16da5d77689b6ac URL: https://github.com/kamailio/kamailio/commit/a10e7652f24bc7ed8e74ff27d16da5d77689b6ac
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2020-04-16T09:40:42+02:00 nathelper: new parameter nat_addr_mode - if set to 0, default private net addresses are checked by nat_uac_test() - if set to 1, other reserved net addresses are checked by nat_uac_test() - default 1 (reserved addresses are considered not routable) - related at GH #2277 --- Modified: src/modules/nathelper/nathelper.c --- Diff: https://github.com/kamailio/kamailio/commit/a10e7652f24bc7ed8e74ff27d16da5d77689b6ac.diff Patch: https://github.com/kamailio/kamailio/commit/a10e7652f24bc7ed8e74ff27d16da5d77689b6ac.patch --- diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c index c5100a466f..65db2a11c3 100644 --- a/src/modules/nathelper/nathelper.c +++ b/src/modules/nathelper/nathelper.c @@ -143,13 +143,16 @@ static int cblen = 0; static int natping_interval = 0; struct socket_info *force_socket = 0; +static int nh_nat_addr_mode = 1; /* clang-format off */ -static struct { +typedef struct nh_netaddr { const char *cnetaddr; uint32_t netaddr; uint32_t mask; -} nets_1918[] = { +} nh_netaddr_t; + +static nh_netaddr_t nh_nets_1918[] = { {"10.0.0.0", 0, 0xffffffffu << 24}, {"172.16.0.0", 0, 0xffffffffu << 20}, {"192.168.0.0", 0, 0xffffffffu << 16}, @@ -157,6 +160,11 @@ static struct { {"192.0.0.0", 0, 0xffffffffu << 3}, /* rfc7335 - IPv4 Service Continuity Prefix */ {NULL, 0, 0} }; + +static nh_netaddr_t nh_nets_extra[] = { + {"192.0.0.0", 0, 0xffffffffu << 8}, /* rfc7335 - IETF Protocol Assignments */ + {NULL, 0, 0} +}; /* clang-format on */ /* @@ -257,6 +265,7 @@ static param_export_t params[] = { {"udpping_from_path", INT_PARAM, &udpping_from_path }, {"append_sdp_oldmediaip", INT_PARAM, &sdp_oldmediaip }, {"filter_server_id", INT_PARAM, &nh_filter_srvid }, + {"nat_addr_mode", INT_PARAM, &nh_nat_addr_mode }, {0, 0, 0} }; @@ -535,10 +544,17 @@ static int mod_init(void) } /* Prepare 1918 networks list */ - for(i = 0; nets_1918[i].cnetaddr != NULL; i++) { - if(inet_aton(nets_1918[i].cnetaddr, &addr) != 1) + for(i = 0; nh_nets_1918[i].cnetaddr != NULL; i++) { + if(inet_aton(nh_nets_1918[i].cnetaddr, &addr) != 1) abort(); - nets_1918[i].netaddr = ntohl(addr.s_addr) & nets_1918[i].mask; + nh_nets_1918[i].netaddr = ntohl(addr.s_addr) & nh_nets_1918[i].mask; + } + + /* Prepare reserved/extra networks list */ + for(i = 0; nh_nets_extra[i].cnetaddr != NULL; i++) { + if(inet_aton(nh_nets_extra[i].cnetaddr, &addr) != 1) + abort(); + nh_nets_extra[i].netaddr = ntohl(addr.s_addr) & nh_nets_extra[i].mask; } register_select_table(sel_declaration); @@ -1267,11 +1283,18 @@ static inline int is1918addr_n(uint32_t netaddr) uint32_t hl; hl = ntohl(netaddr); - for(i = 0; nets_1918[i].cnetaddr != NULL; i++) { - if((hl & nets_1918[i].mask) == nets_1918[i].netaddr) { + for(i = 0; nh_nets_1918[i].cnetaddr != NULL; i++) { + if((hl & nh_nets_1918[i].mask) == nh_nets_1918[i].netaddr) { return 1; } } + if(nh_nat_addr_mode==1) { + for(i = 0; nh_nets_extra[i].cnetaddr != NULL; i++) { + if((hl & nh_nets_extra[i].mask) == nh_nets_extra[i].netaddr) { + return 1; + } + } + } return 0; } _______________________________________________ Kamailio (SER) - Development Mailing List [email protected] https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
