From 6adfd81bbd890b6efe6d11063d09131bc665d45c Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 4 Apr 2016 19:19:09 +0200 Subject: [PATCH] Add EUI{48,64} RRType support --- Makefile | 12 +++++++--- eui48.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ eui64.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ main.c | 2 ++ rr.c | 11 +++++++++- rr.h | 16 ++++++++++++++ t/zones/example.sec | 3 +++ 7 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 eui48.c create mode 100644 eui64.c diff --git a/Makefile b/Makefile index 0263974..a67f172 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ validns: main.o carp.o mempool.o textparse.o base64.o base32hex.o \ dname.o tlsa.o nid.o l32.o l64.o lp.o \ ipseckey.o cbtree.o mb.o mg.o mr.o minfo.o \ afsdb.o x25.o isdn.o rt.o px.o kx.o \ - dlv.o dhcid.o nsap.o caa.o + dlv.o dhcid.o nsap.o caa.o eui48.o eui64.o $(CC) $(CFLAGS) $(OPTIMIZE) -o validns \ main.o carp.o mempool.o textparse.o base64.o base32hex.o \ rr.o soa.o a.o cname.o mx.o ns.o \ @@ -38,7 +38,7 @@ validns: main.o carp.o mempool.o textparse.o base64.o base32hex.o \ dname.o tlsa.o nid.o l32.o l64.o lp.o \ ipseckey.o cbtree.o mb.o mg.o mr.o minfo.o \ afsdb.o x25.o isdn.o rt.o px.o kx.o \ - dlv.o dhcid.o nsap.o caa.o \ + dlv.o dhcid.o nsap.o caa.o eui48.o eui64.o \ -L/usr/local/lib -L/opt/local/lib $(EXTRALPATH) \ -lJudy -lcrypto $(EXTRALIBS) $(EXTRALINKING) @@ -53,7 +53,7 @@ clean: -rm -f nid.o l32.o l64.o lp.o ipseckey.o -rm -f cbtree.o mb.o mg.o mr.o minfo.o -rm -f afsdb.o x25.o isdn.o rt.o px.o kx.o - -rm -f dlv.o dhcid.o nsap.o caa.o + -rm -f dlv.o dhcid.o nsap.o caa.o eui48.o eui64.o -rm -f validns.core core @echo ':-)' @@ -141,6 +141,12 @@ nsec.o: nsec.c common.h textparse.h mempool.h carp.h rr.h dnskey.o: dnskey.c common.h textparse.h mempool.h carp.h rr.h $(CC) $(CFLAGS) $(OPTIMIZE) -c -o dnskey.o dnskey.c $(INCPATH) +eui48.o: eui48.c textparse.h mempool.h carp.h rr.h + $(CC) $(CFLAGS) $(OPTIMIZE) -c -o eui48.o eui48.c $(INCPATH) + +eui64.o: eui64.c textparse.h mempool.h carp.h rr.h + $(CC) $(CFLAGS) $(OPTIMIZE) -c -o eui64.o eui64.c $(INCPATH) + txt.o: txt.c common.h textparse.h mempool.h carp.h rr.h $(CC) $(CFLAGS) $(OPTIMIZE) -c -o txt.o txt.c $(INCPATH) diff --git a/eui48.c b/eui48.c new file mode 100644 index 0000000..9062072 --- /dev/null +++ b/eui48.c @@ -0,0 +1,52 @@ +/* + * Part of DNS zone file validator `validns`. + * + * Copyright 2016 Pieter Lexis + * Modified BSD license. + * (See LICENSE file in the distribution.) + * + */ +#include +#include +#include +#include +#include + +#include "common.h" +#include "textparse.h" +#include "mempool.h" +#include "carp.h" +#include "rr.h" + +static struct rr* eui48_parse(char *name, long ttl, int type, char *s) +{ + struct rr_eui48 *rr = getmem(sizeof(*rr)); + uint8_t r[6]; + + if (sscanf(s, "%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx", + r, r+1, r+2, r+3, r+4, r+5) != 6) { + return bitch("%s: in wrong format", name); + } + + memmove(rr->address, r, 6); + + return store_record(type, name, ttl, rr); +} + +static struct binary_data eui48_wirerdata(struct rr *rrv) +{ + RRCAST(eui48); + struct binary_data r; + + r.length = sizeof(rr->address); + r.data = (void *)&rr->address; + + return r; +} + +static char* eui48_human(struct rr *rrv) +{ + return "..."; +} + +struct rr_methods eui48_methods = { eui48_parse, eui48_human, eui48_wirerdata, NULL, NULL }; diff --git a/eui64.c b/eui64.c new file mode 100644 index 0000000..d9fb288 --- /dev/null +++ b/eui64.c @@ -0,0 +1,53 @@ +/* + * Part of DNS zone file validator `validns`. + * + * Copyright 2016 Pieter Lexis + * Modified BSD license. + * (See LICENSE file in the distribution.) + * + */ +#include +#include +#include +#include +#include + +#include "common.h" +#include "textparse.h" +#include "mempool.h" +#include "carp.h" +#include "rr.h" + +static struct rr* eui64_parse(char *name, long ttl, int type, char *s) +{ + struct rr_eui64 *rr = getmem(sizeof(*rr)); + uint8_t r[8]; + + if (sscanf(s, "%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx", + r+0, r+1, r+2, r+3, r+4, r+5, r+6, r+7) != 8) { + return bitch("%s: in wrong format", name); + } + + memmove(rr->address, r, 8); + + return store_record(type, name, ttl, rr); +} + +static struct binary_data eui64_wirerdata(struct rr *rrv) +{ + RRCAST(eui64); + struct binary_data r; + + r.length = sizeof(rr->address); + r.data = (void *)&rr->address; + + return r; +} + +static char* eui64_human(struct rr *rrv) +{ + return "..."; +} + +struct rr_methods eui64_methods = { eui64_parse, eui64_human, eui64_wirerdata, NULL, NULL }; + diff --git a/main.c b/main.c index 89a20de..41c0777 100644 --- a/main.c +++ b/main.c @@ -487,6 +487,8 @@ static void initialize_globals(void) rr_methods[T_DNAME] = dname_methods; rr_methods[T_DNSKEY] = dnskey_methods; rr_methods[T_DS] = ds_methods; + rr_methods[T_EUI48] = eui48_methods; + rr_methods[T_EUI64] = eui64_methods; rr_methods[T_HINFO] = hinfo_methods; rr_methods[T_IPSECKEY] = ipseckey_methods; rr_methods[T_ISDN] = isdn_methods; diff --git a/rr.c b/rr.c index c7ab12e..80699d5 100644 --- a/rr.c +++ b/rr.c @@ -88,7 +88,9 @@ static char* rdtype2str_map[T_MAX+1] = { "L32", "L64", "LP", - 0, 0, 0, /* 110 */ + "EUI48", + "EUI64", + 0, /* 110 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 120 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 130 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 140 */ @@ -528,6 +530,13 @@ int str2rdtype(char *rdtype, int *is_generic) return T_DHCID; } break; + case 'e': + if (strcmp(rdtype, "eui48") == 0) { + return T_EUI48; + } else if (strcmp(rdtype, "eui64") == 0) { + return T_EUI64; + } + break; case 'h': if (strcmp(rdtype, "hinfo") == 0) { return T_HINFO; diff --git a/rr.h b/rr.h index a2d39b2..203951c 100644 --- a/rr.h +++ b/rr.h @@ -53,6 +53,8 @@ #define T_L32 105 #define T_L64 106 #define T_LP 107 +#define T_EUI48 108 +#define T_EUI64 109 #define T_CAA 257 #define T_DLV 32769 #define T_MAX 32769 @@ -505,6 +507,20 @@ struct rr_dlv }; extern struct rr_methods dlv_methods; +struct rr_eui48 +{ + struct rr rr; + uint8_t address[6]; +}; +extern struct rr_methods eui48_methods; + +struct rr_eui64 +{ + struct rr rr; + uint8_t address[8]; +}; +extern struct rr_methods eui64_methods; + struct rr_nsap { struct rr rr; diff --git a/t/zones/example.sec b/t/zones/example.sec index 47f98d3..5de5eed 100644 --- a/t/zones/example.sec +++ b/t/zones/example.sec @@ -122,3 +122,6 @@ sec-32 IPSECKEY ( 10 3 2 some.name. AQO/C76MVA5WN743YYeE537SLNffRZvQ9yxoQqJP943g sec-mixed-30 IPSECKEY ( 10 3 0 sOme.naMe. ) sec-mixed-31 IPSECKEY ( 10 3 1 Some.namE. AQO/C76MVA5WN743YYeE537SLNffRZvQ9yxoQqJP943gqs4QATtnJWHQ 1SDWiRE2aXl7SJoyJAu7jaUTGKWXzStD2wpkBIJ1IZ+avxf8zxRt3y6x ImvMjRqcobreI351nbop04aBtP7o+r0zrNQmy6FqkPiI657FMEdF1cWJ 2Q4lA0Pymgq/BadXymj/LZXpmCtnTNU6laUUGuxxaf0Fj+vcL17OvU1k sLs9/9hhAbYYedmbAAGmAqfICiLBdOPCbhsCUyq8dTa0FaEinyHCJSHJ WVZ8dBpbbr2pQnZ5ul5NCgkhhcr26IPPiZm2eww6ougsogj6kPdSSQYZ YayHzVnl8NFQ9uCwbRTryepPzZP5Vd2t ) sec-mixed-32 IPSECKEY ( 10 3 2 soMe.NAme. AQO/C76MVA5WN743YYeE537SLNffRZvQ9yxoQqJP943gqs4QATtnJWHQ 1SDWiRE2aXl7SJoyJAu7jaUTGKWXzStD2wpkBIJ1IZ+avxf8zxRt3y6x ImvMjRqcobreI351nbop04aBtP7o+r0zrNQmy6FqkPiI657FMEdF1cWJ 2Q4lA0Pymgq/BadXymj/LZXpmCtnTNU6laUUGuxxaf0Fj+vcL17OvU1k sLs9/9hhAbYYedmbAAGmAqfICiLBdOPCbhsCUyq8dTa0FaEinyHCJSHJ WVZ8dBpbbr2pQnZ5ul5NCgkhhcr26IPPiZm2eww6ougsogj6kPdSSQYZ YayHzVnl8NFQ9uCwbRTryepPzZP5Vd2t ) + +sec-eui48 EUI48 00-50-56-9b-00-e7 +sec-eui64 EUI64 00-50-56-9b-00-e7-7e-57