[sr-dev] git:master:d48ce56d: core: new parameter ipv6_hex_style

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 30 09:20:29 CEST 2020


Module: kamailio
Branch: master
Commit: d48ce56dcd382786d9e81c5477341a8899e0b338
URL: https://github.com/kamailio/kamailio/commit/d48ce56dcd382786d9e81c5477341a8899e0b338

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-09-30T09:17:03+02:00

core: new parameter ipv6_hex_style

- can be set to "a" or "A" to specify if hex digits in local computed
ipv6 addresses are lowercase or uppercase. Default is "A" (same format
used so far).
- enables the ability to follow recommedations of RFC5952, section 4.3
- GH #2488

---

Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/core/ip_addr.c
Modified: src/core/ip_addr.h

---

Diff:  https://github.com/kamailio/kamailio/commit/d48ce56dcd382786d9e81c5477341a8899e0b338.diff
Patch: https://github.com/kamailio/kamailio/commit/d48ce56dcd382786d9e81c5477341a8899e0b338.patch

---

diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index d5ac31ddd8..cc565b0151 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -331,6 +331,8 @@ DNS_CACHE_REC_PREF	dns_cache_rec_pref
 /* ipv6 auto bind */
 AUTO_BIND_IPV6		auto_bind_ipv6
 BIND_IPV6_LINK_LOCAL	bind_ipv6_link_local
+IPV6_HEX_STYLE		ipv6_hex_style
+
 /* blacklist */
 DST_BLST_INIT	dst_blacklist_init
 USE_DST_BLST		use_dst_blacklist
@@ -775,6 +777,8 @@ IMPORTFILE      "import_file"
 								return AUTO_BIND_IPV6; }
 <INITIAL>{BIND_IPV6_LINK_LOCAL}	{ count(); yylval.strval=yytext;
 								return BIND_IPV6_LINK_LOCAL; }
+<INITIAL>{IPV6_HEX_STYLE}	{ count(); yylval.strval=yytext;
+								return IPV6_HEX_STYLE; }
 <INITIAL>{DST_BLST_INIT}	{ count(); yylval.strval=yytext;
 								return DST_BLST_INIT; }
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
diff --git a/src/core/cfg.y b/src/core/cfg.y
index d17540de72..7fc9817a6f 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -360,6 +360,8 @@ extern char *default_routename;
 %token AUTO_BIND_IPV6
 %token BIND_IPV6_LINK_LOCAL
 
+%token IPV6_HEX_STYLE
+
 /*blacklist*/
 %token DST_BLST_INIT
 %token USE_DST_BLST
@@ -875,6 +877,13 @@ assign_stm:
 	| DNS_CACHE_REC_PREF error { yyerror("boolean value expected"); }
 	| AUTO_BIND_IPV6 EQUAL NUMBER {IF_AUTO_BIND_IPV6(auto_bind_ipv6 = $3);}
 	| AUTO_BIND_IPV6 error { yyerror("boolean value expected"); }
+	| IPV6_HEX_STYLE EQUAL STRING {
+		ksr_ipv6_hex_style = $3;
+		if(ksr_ipv6_hex_style[0]!='a' && ksr_ipv6_hex_style[0]!='A') {
+			yyerror("expected \"a\" or \"A\" value");
+		}
+	}
+	| IPV6_HEX_STYLE error { yyerror("string value expected"); }
 	| BIND_IPV6_LINK_LOCAL EQUAL NUMBER {sr_bind_ipv6_link_local = $3;}
 	| BIND_IPV6_LINK_LOCAL error { yyerror("boolean value expected"); }
 	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
diff --git a/src/core/globals.h b/src/core/globals.h
index ea16f3ae29..6e5b234353 100644
--- a/src/core/globals.h
+++ b/src/core/globals.h
@@ -219,6 +219,7 @@ extern char *_sr_uri_host_extra_chars;
 extern unsigned char *_ksr_hname_extra_chars;
 
 extern char *ksr_stats_namesep;
+extern char *ksr_ipv6_hex_style;
 
 #ifdef USE_DNS_CACHE
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
diff --git a/src/core/ip_addr.c b/src/core/ip_addr.c
index 9989063fff..4dada18ddc 100644
--- a/src/core/ip_addr.c
+++ b/src/core/ip_addr.c
@@ -36,6 +36,7 @@
 #include "resolve.h"
 #include "trim.h"
 
+char *ksr_ipv6_hex_style = "A";
 
 struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask)
 {
diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h
index bfde61cdec..53880b0059 100644
--- a/src/core/ip_addr.h
+++ b/src/core/ip_addr.h
@@ -41,6 +41,8 @@
 
 #include "dprint.h"
 
+extern char *ksr_ipv6_hex_style;
+
 enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP,
 	PROTO_WS, PROTO_WSS, PROTO_OTHER };
 #define PROTO_LAST PROTO_OTHER
@@ -530,7 +532,7 @@ static inline int ip6tosbuf(unsigned char* ip6, char* buff, int len)
 	register unsigned short hex4;
 	int r;
 
-#define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0')
+#define HEXDIG(x) (((x)>=10)?(x)-10+ksr_ipv6_hex_style[0]:(x)+'0')
 
 	offset=0;
 	if (unlikely(len<IP6_MAX_STR_SIZE))




More information about the sr-dev mailing list