Browse code

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

Daniel-Constantin Mierla authored on 30/09/2020 07:17:03
Showing 5 changed files
... ...
@@ -331,6 +331,8 @@ DNS_CACHE_REC_PREF	dns_cache_rec_pref
331 331
 /* ipv6 auto bind */
332 332
 AUTO_BIND_IPV6		auto_bind_ipv6
333 333
 BIND_IPV6_LINK_LOCAL	bind_ipv6_link_local
334
+IPV6_HEX_STYLE		ipv6_hex_style
335
+
334 336
 /* blacklist */
335 337
 DST_BLST_INIT	dst_blacklist_init
336 338
 USE_DST_BLST		use_dst_blacklist
... ...
@@ -775,6 +777,8 @@ IMPORTFILE      "import_file"
775 777
 								return AUTO_BIND_IPV6; }
776 778
 <INITIAL>{BIND_IPV6_LINK_LOCAL}	{ count(); yylval.strval=yytext;
777 779
 								return BIND_IPV6_LINK_LOCAL; }
780
+<INITIAL>{IPV6_HEX_STYLE}	{ count(); yylval.strval=yytext;
781
+								return IPV6_HEX_STYLE; }
778 782
 <INITIAL>{DST_BLST_INIT}	{ count(); yylval.strval=yytext;
779 783
 								return DST_BLST_INIT; }
780 784
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
... ...
@@ -360,6 +360,8 @@ extern char *default_routename;
360 360
 %token AUTO_BIND_IPV6
361 361
 %token BIND_IPV6_LINK_LOCAL
362 362
 
363
+%token IPV6_HEX_STYLE
364
+
363 365
 /*blacklist*/
364 366
 %token DST_BLST_INIT
365 367
 %token USE_DST_BLST
... ...
@@ -875,6 +877,13 @@ assign_stm:
875 877
 	| DNS_CACHE_REC_PREF error { yyerror("boolean value expected"); }
876 878
 	| AUTO_BIND_IPV6 EQUAL NUMBER {IF_AUTO_BIND_IPV6(auto_bind_ipv6 = $3);}
877 879
 	| AUTO_BIND_IPV6 error { yyerror("boolean value expected"); }
880
+	| IPV6_HEX_STYLE EQUAL STRING {
881
+		ksr_ipv6_hex_style = $3;
882
+		if(ksr_ipv6_hex_style[0]!='a' && ksr_ipv6_hex_style[0]!='A') {
883
+			yyerror("expected \"a\" or \"A\" value");
884
+		}
885
+	}
886
+	| IPV6_HEX_STYLE error { yyerror("string value expected"); }
878 887
 	| BIND_IPV6_LINK_LOCAL EQUAL NUMBER {sr_bind_ipv6_link_local = $3;}
879 888
 	| BIND_IPV6_LINK_LOCAL error { yyerror("boolean value expected"); }
880 889
 	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
... ...
@@ -219,6 +219,7 @@ extern char *_sr_uri_host_extra_chars;
219 219
 extern unsigned char *_ksr_hname_extra_chars;
220 220
 
221 221
 extern char *ksr_stats_namesep;
222
+extern char *ksr_ipv6_hex_style;
222 223
 
223 224
 #ifdef USE_DNS_CACHE
224 225
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
... ...
@@ -36,6 +36,7 @@
36 36
 #include "resolve.h"
37 37
 #include "trim.h"
38 38
 
39
+char *ksr_ipv6_hex_style = "A";
39 40
 
40 41
 struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask)
41 42
 {
... ...
@@ -41,6 +41,8 @@
41 41
 
42 42
 #include "dprint.h"
43 43
 
44
+extern char *ksr_ipv6_hex_style;
45
+
44 46
 enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP,
45 47
 	PROTO_WS, PROTO_WSS, PROTO_OTHER };
46 48
 #define PROTO_LAST PROTO_OTHER
... ...
@@ -530,7 +532,7 @@ static inline int ip6tosbuf(unsigned char* ip6, char* buff, int len)
530 532
 	register unsigned short hex4;
531 533
 	int r;
532 534
 
533
-#define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0')
535
+#define HEXDIG(x) (((x)>=10)?(x)-10+ksr_ipv6_hex_style[0]:(x)+'0')
534 536
 
535 537
 	offset=0;
536 538
 	if (unlikely(len<IP6_MAX_STR_SIZE))