Skip to content

Commit

Permalink
Add EUI{48,64} RRType support
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis committed Sep 25, 2017
1 parent f423245 commit 6adfd81
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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)

Expand All @@ -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 ':-)'

Expand Down Expand Up @@ -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)

Expand Down
52 changes: 52 additions & 0 deletions eui48.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2016 Pieter Lexis <[email protected]>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#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 };
53 changes: 53 additions & 0 deletions eui64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2016 Pieter Lexis <[email protected]>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#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 };

2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions rr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions t/zones/example.sec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6adfd81

Please sign in to comment.