Kaynağa Gözat

Added support for encode for TLV 202.53.2.1 and TLV 202.53.2.1

AdrianSimionov 10 yıl önce
ebeveyn
işleme
7476411e84
6 değiştirilmiş dosya ile 48 ekleme ve 6 silme
  1. 0 3
      README.md
  2. 39 0
      src/docsis_encode.c
  3. 1 0
      src/docsis_encode.h
  4. 3 1
      src/docsis_lex.l
  5. 2 2
      src/docsis_symtable.h
  6. 3 0
      src/docsis_yy.y

+ 0 - 3
README.md

@@ -61,6 +61,3 @@ Known issues
 ------------
 
 Quoting the hex strings will result in a crash. Do not use something similar to "0xABCD".
-
-Following TLVs can only be decoded but not encoded: SNMPv1v2cTransportAddress, SNMPv1v2cTransportAddressMask.
-

+ 39 - 0
src/docsis_encode.c

@@ -240,6 +240,45 @@ int encode_char_ip_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym
   }
 }
 
+int encode_ip_ip6_port( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
+{
+  struct in6_addr in6;
+  struct in_addr in;
+  int i;
+  short int port;
+  char *token;
+  char *array[2];
+  const char s[2] = "/";
+  
+  union t_val *helper; /* We only use this to cast the void* we receive to what we think it should be */
+  
+  helper = (union t_val *) tval;
+  
+  i = 0;
+  token = strtok(helper->strval, s);
+  while (token != NULL)
+  {
+    array[i++] = token;
+    token = strtok (NULL, s);
+  }
+  port = htons(atoi(array[1]));
+  
+  if ( inet_pton(AF_INET6, array[0], &in6) ) {
+    memcpy ( buf, &in6, sizeof(struct in6_addr));
+    memcpy ( buf + sizeof(struct in6_addr),&port,sizeof(unsigned short));
+    free(helper->strval);
+    return ( sizeof(struct in6_addr) + sizeof(unsigned short));
+  } else if ( inet_aton ( array[0], &in) ) {
+    memcpy ( buf, &in, sizeof(struct in_addr));
+    memcpy ( buf + sizeof(struct in_addr),&port,sizeof(unsigned short));
+    free(helper->strval);
+    return ( sizeof(struct in_addr) + sizeof(unsigned short));    
+  } else {
+    fprintf(stderr, "Invalid IP address / port combination %s at line %d\n", helper->strval, line );
+    exit (-1);
+  }
+}
+
 int encode_lenzero( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
   return (0);

+ 1 - 0
src/docsis_encode.h

@@ -32,6 +32,7 @@ int encode_ip     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 int encode_ip6     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip_ip6  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_char_ip_ip6  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
+int encode_ip_ip6_port  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_lenzero  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ether	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_dual_qtag	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );

+ 3 - 1
src/docsis_lex.l

@@ -62,7 +62,8 @@ char *tsave;
 ([0-9]+,){9}[0-9]+		{ TSAVE(yytext);yylval.strval=tsave; return T_SUBMGT_FILTERS;	  }
 ([0-9]+\.){3}[0-9]+	 	{ TSAVE(yytext);yylval.strval=tsave; return T_IP;	  }
 0[Xx]([0-9A-Fa-f])+		{ TSAVE(yytext);yylval.strval=tsave; return T_HEX_STRING; }
-([0-9A-Fa-f][0-9A-Fa-f]:){5}[0-9A-Fa-f][0-9A-Fa-f]\/([0-9A-Fa-f][0-9A-Fa-f]:){5}[0-9A-Fa-f][0-9A-Fa-f]  { TSAVE(yytext);yylval.strval=tsave; return T_ETHERMASK; 			       }
+([0-9A-Fa-f][0-9A-Fa-f]:){5}[0-9A-Fa-f][0-9A-Fa-f]\/([0-9A-Fa-f][0-9A-Fa-f]:){5}[0-9A-Fa-f][0-9A-Fa-f]  { TSAVE(yytext);yylval.strval=tsave; return T_ETHERMASK; }
+([0-9]+\.){3}[0-9]+\/[0-9]+	 	{ TSAVE(yytext);yylval.strval=tsave; return T_IP_IP6_PORT; }
 ([0-9A-Fa-f][0-9A-Fa-f]:){5}[0-9A-Fa-f][0-9A-Fa-f]  { TSAVE(yytext);yylval.strval=tsave; return T_MAC; 			       }
 
 (\.{1})*([A-Za-z0-9_-]+\.)+[A-Za-z0-9]+	{ TSAVE(yytext);yylval.strval=tsave; return T_LABEL_OID; }
@@ -155,6 +156,7 @@ TlvType			{ return T_TLV_TYPE;		}
 .	 { fprintf(stderr, "Unrecognized char \"%c\" at line %d\n",*yytext,line); exit(-1); }
 (::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))		{ TSAVE(yytext);yylval.strval=tsave; return T_IP6;	  }
 [0-9]+,[0-9]+ 				{ TSAVE(yytext);yylval.strval=tsave; return T_DUAL_TAG; }
+(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))\/[0-9]+		{ TSAVE(yytext);yylval.strval=tsave; return T_IP_IP6_PORT;	  }
 %%
 
 struct symbol_entry

+ 2 - 2
src/docsis_symtable.h

@@ -510,8 +510,8 @@ symbol_type symtable[NUM_IDENTIFIERS] =  {
 { 228,    "SNMPv1v2cCoexistenceConfig",        53,     175,    (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 202.53 eRouter-I12 Annex B.4.5 */
 { 229,    "SNMPv1v2cCommunityName",            1,      228,    (encode_string),         (decode_string),         0,           0             }, /* TLV 202.53.1 eRouter-I12 Annex B.4.5.1 */
 { 230,    "SNMPv1v2cTransportAddressAccess",   2,      228,    (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 202.53.2 eRouter-I12 Annex B.4.5.2 */
-{ 340,    "SNMPv1v2cTransportAddress",         1,      230,    (encode_nothing),        (decode_ip_ip6_port),    0,           0             }, /* TLV 202.53.2.1 eRouter-I12 Annex B.4.5.2.1 */
-{ 349,    "SNMPv1v2cTransportAddressMask",     2,      230,    (encode_nothing),        (decode_ip_ip6_port),    0,           0             }, /* TLV 202.53.2.2 eRouter-I12 Annex B.4.5.2.2 */
+{ 340,    "SNMPv1v2cTransportAddress",         1,      230,    (encode_ip_ip6_port),    (decode_ip_ip6_port),    0,           0             }, /* TLV 202.53.2.1 eRouter-I12 Annex B.4.5.2.1 */
+{ 349,    "SNMPv1v2cTransportAddressMask",     2,      230,    (encode_ip_ip6_port),    (decode_ip_ip6_port),    0,           0             }, /* TLV 202.53.2.2 eRouter-I12 Annex B.4.5.2.2 */
 { 231,    "SNMPv1v2cAccessViewType",           3,      228,    (encode_uchar),          (decode_uchar),          1,           2             }, /* TLV 202.53.3 eRouter-I12 Annex B.4.5.3 */
 { 232,    "SNMPv1v2cAccessViewName",           4,      228,    (encode_string),         (decode_string),         0,           0             }, /* TLV 202.53.4 eRouter-I12 Annex B.4.5.4 */
 { 233,    "SNMPv3AccessViewConfiguration",     54,     175,    (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 202.54 eRouter-I12 Annex B.4.6 */

+ 3 - 0
src/docsis_yy.y

@@ -96,6 +96,7 @@ struct tlv *_my_tlvtree_head;
 %token <uintval>  T_TLV_STRZERO_VALUE
 %token <uintval>  T_TLV_TYPE
 %token <uintval>  T_DUAL_TAG
+%token <uintval>  T_IP_IP6_PORT
 
 %type <tlvptr>  assignment_stmt
 %type <tlvptr>  generic_stmt
@@ -173,6 +174,8 @@ assignment_stmt:  T_IDENTIFIER T_INTEGER ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 		| T_IDENTIFIER T_DUAL_TAG ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
+		| T_IDENTIFIER T_IP_IP6_PORT ';' {
+			$$ = create_tlv ($1, (union t_val *)&$2);}			
 		| T_IDENTIFIER T_MAC ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 		| T_IDENTIFIER T_ETHERMASK ';' {