2
0
Эх сурвалжийг харах

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 5 жил өмнө
parent
commit
d48ce56dcd

+ 4 - 0
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;

+ 9 - 0
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); }

+ 1 - 0
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 */

+ 1 - 0
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)
 {

+ 3 - 1
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))