Browse Source

IPv6 Support

Benedikt Schirrmeister 13 years ago
parent
commit
8498173494
8 changed files with 74 additions and 1 deletions
  1. 1 1
      src/docsis_common.h
  2. 25 0
      src/docsis_decode.c
  3. 3 0
      src/docsis_decode.h
  4. 34 0
      src/docsis_encode.c
  5. 1 0
      src/docsis_encode.h
  6. 3 0
      src/docsis_lex.l
  7. 4 0
      src/docsis_symtable.h
  8. 3 0
      src/docsis_yy.y

+ 1 - 1
src/docsis_common.h

@@ -31,7 +31,7 @@
 
 
 
 
 #ifndef NUM_IDENTIFIERS
 #ifndef NUM_IDENTIFIERS
-#define NUM_IDENTIFIERS 175
+#define NUM_IDENTIFIERS 177
 #endif /*  NUM_IDENTIFIERS, needed in docsis_symtable.h  */
 #endif /*  NUM_IDENTIFIERS, needed in docsis_symtable.h  */
 
 
 #define MAXINT 2000000000
 #define MAXINT 2000000000

+ 25 - 0
src/docsis_decode.c

@@ -20,6 +20,14 @@
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  */
  */
 
 
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+
 #include <math.h>
 #include <math.h>
 #include <ctype.h>
 #include <ctype.h>
 
 
@@ -30,6 +38,9 @@
 #include "ethermac.h"
 #include "ethermac.h"
 
 
 
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
 struct symbol_entry *
 struct symbol_entry *
 find_symbol_by_code_and_pid (unsigned char code, unsigned int pid)
 find_symbol_by_code_and_pid (unsigned char code, unsigned int pid)
 {
 {
@@ -88,6 +99,20 @@ void decode_ip (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 	sym->sym_ident, inet_ntoa(helper) );
 	sym->sym_ident, inet_ntoa(helper) );
 }
 }
 
 
+void decode_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length )
+{
+  static struct in6_addr helper;
+  char ipstr[INET6_ADDRSTRLEN];
+  if (length != sizeof(struct in6_addr) ) {
+        printf("ip address length mismatch!\n");
+        exit(-45);
+  }
+
+  memcpy (&helper, tlvbuf, length );
+  printf ( "%s %s;\n",
+	sym->sym_ident, inet_ntop(AF_INET6,tlvbuf,ipstr,sizeof ipstr) );
+}
+
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 {
 {
 
 

+ 3 - 0
src/docsis_decode.h

@@ -20,6 +20,8 @@
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  */
  */
 
 
+/*IPv6-Function inspired by http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html */ 
+
 #ifndef _DOCSIS_DECODE_H
 #ifndef _DOCSIS_DECODE_H
 #define _DOCSIS_DECODE_H
 #define _DOCSIS_DECODE_H
 
 
@@ -33,6 +35,7 @@ void decode_uint (unsigned char *tlvbuf, struct symbol_entry *sym, size_t length
 void decode_ushort (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ushort (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_uchar (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_uchar (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip (unsigned char *tlvbuf, symbol_type *sym, size_t length );
+void decode_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ethermask (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ethermask (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_md5 (unsigned char *tlvbuf, symbol_type *sym, size_t length);
 void decode_md5 (unsigned char *tlvbuf, symbol_type *sym, size_t length);

+ 34 - 0
src/docsis_encode.c

@@ -20,6 +20,10 @@
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  */
  */
 
 
+#include <netdb.h>
+
+
+
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -131,6 +135,7 @@ int encode_uchar ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 }
 }
 
 
 
 
+
 int encode_ip( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 int encode_ip( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
 {
   struct in_addr in;
   struct in_addr in;
@@ -160,6 +165,35 @@ int encode_ip( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
   return ( sizeof(struct in_addr));
   return ( sizeof(struct in_addr));
 }
 }
 
 
+int encode_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
+{
+struct in6_addr in;
+int retval; 	     /* return value of inet_aton */
+union t_val *helper; /* We only use this to cast the void* we receive to what we think it should be */
+
+  if ( buf == NULL ) {
+        printf ("encode_ip called w/NULL buffer!\n");
+        exit (-1);
+  }
+
+  if ( tval == NULL  ) {
+        printf ("encode_ip called w/NULL value struct !\n");
+        exit (-1);
+  }
+
+  helper = (union t_val *) tval;
+
+  if (!(retval = inet_pton(AF_INET6, helper->strval, &in)) ) {
+	printf ( "Invalid IP address %s at line %d", helper->strval, line );
+	exit (-1);
+  }
+#ifdef DEBUG
+  printf ("encode_ip: found %s at line %d\n",inet_ntoa(in), line);
+#endif /* DEBUG */
+  memcpy ( buf, &in, sizeof(struct in6_addr));
+  free(helper->strval);
+  return ( sizeof(struct in6_addr));
+}
 
 
 int encode_ether ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 int encode_ether ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
 {

+ 1 - 0
src/docsis_encode.h

@@ -29,6 +29,7 @@ int encode_uint   	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 int encode_ushort 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ushort 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_uchar  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_uchar  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 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_ether	(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_ethermask	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ethermask	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_string 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_string 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );

+ 3 - 0
src/docsis_lex.l

@@ -20,6 +20,8 @@
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  *  DOCSIS is a registered trademark of Cablelabs, http://www.cablelabs.com
  */
  */
 
 
+/* IPv6 RegEx lent from http://www.regexlib.com/REDetails.aspx?regexp_id=2919 Author: mij */
+
 %{
 %{
 #include "docsis.h"
 #include "docsis.h"
 #include "docsis_yy.h"
 #include "docsis_yy.h"
@@ -132,6 +134,7 @@ TlvType			{ return T_TLV_TYPE;		}
 \}	 { yylval.strval=yytext;return '}'; }
 \}	 { yylval.strval=yytext;return '}'; }
 ;	 { yylval.strval=yytext;return ';'; }
 ;	 { yylval.strval=yytext;return ';'; }
 .	 { printf("Unrecognized char \"%c\" at line %d\n",*yytext,line); exit(-1); }
 .	 { printf("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;	  }
 %%
 %%
 
 
 struct symbol_entry
 struct symbol_entry

+ 4 - 0
src/docsis_symtable.h

@@ -259,6 +259,10 @@ symbol_type symtable[NUM_IDENTIFIERS] =  {
 { 171, "CoSignerCVCData",      		33,   0,  (encode_hexstr),    (decode_hexstr),      0,        255    },
 { 171, "CoSignerCVCData",      		33,   0,  (encode_hexstr),    (decode_hexstr),      0,        255    },
 { 172, "CoSignerCVC",      		33,   0,  (encode_nothing),    (decode_hexstr),      0,        255    },
 { 172, "CoSignerCVC",      		33,   0,  (encode_nothing),    (decode_hexstr),      0,        255    },
 
 
+/*IPv6-Tests ... */
+{ 173,  "SwUpgradeServer6",    	58,  0,   (encode_ip6),        (decode_ip6),          0,        0          },
+{ 174, "SubMgmtControl6", 		63,  0,	  (encode_hexstr),    (decode_hexstr), 		2,	2 	},
+
 /* Generic TLV ... we only use the limits, code and length don't matter ...*/
 /* Generic TLV ... we only use the limits, code and length don't matter ...*/
 { 998, "GenericTLV",           		0, 0,     (encode_nothing),   (decode_special),  0,        0        },
 { 998, "GenericTLV",           		0, 0,     (encode_nothing),   (decode_special),  0,        0        },
 { 999, "/*EndOfDataMkr*/",     		255, 0,   (encode_nothing),   (decode_special),  0,        0          }
 { 999, "/*EndOfDataMkr*/",     		255, 0,   (encode_nothing),   (decode_special),  0,        0          }

+ 3 - 0
src/docsis_yy.y

@@ -65,6 +65,7 @@ struct tlv *_my_tlvtree_head;
 %token <strval>  T_LABEL_OID
 %token <strval>  T_LABEL_OID
 %token <strval>  T_SUBMGT_FILTERS
 %token <strval>  T_SUBMGT_FILTERS
 %token <strval>  T_IP
 %token <strval>  T_IP
+%token <strval>  T_IP6
 %token <strval>  T_MAC
 %token <strval>  T_MAC
 %token <strval>  T_MAIN
 %token <strval>  T_MAIN
 %token <strval>  T_STRING
 %token <strval>  T_STRING
@@ -168,6 +169,8 @@ assignment_stmt:  T_IDENTIFIER T_INTEGER ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 		| T_IDENTIFIER T_IP ';' {
 		| T_IDENTIFIER T_IP ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 			$$ = create_tlv ($1, (union t_val *)&$2);}
+		| T_IDENTIFIER T_IP6 ';' {
+			$$ = create_tlv ($1, (union t_val *)&$2);}
 		| T_IDENTIFIER T_MAC ';' {
 		| T_IDENTIFIER T_MAC ';' {
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 			$$ = create_tlv ($1, (union t_val *)&$2);}
 		| T_IDENTIFIER T_ETHERMASK ';' {
 		| T_IDENTIFIER T_ETHERMASK ';' {