added qse_ip6adxx_t with address classification functions
defined data types and routines and dhcpv6 messages
This commit is contained in:
parent
2915a591f0
commit
e936bf3502
@ -166,7 +166,7 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/README.in \
|
||||
$(top_srcdir)/ac/config.guess $(top_srcdir)/ac/config.sub \
|
||||
$(top_srcdir)/ac/install-sh $(top_srcdir)/ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/missing ac/ar-lib ac/compile ac/config.guess \
|
||||
ac/config.sub ac/depcomp ac/install-sh ac/ltmain.sh ac/missing
|
||||
ac/config.sub ac/install-sh ac/ltmain.sh ac/missing
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
distdir = $(PACKAGE)-$(VERSION)
|
||||
top_distdir = $(distdir)
|
||||
|
@ -40,6 +40,35 @@ struct qse_ip4ad_t
|
||||
qse_uint32_t value;
|
||||
};
|
||||
|
||||
struct qse_ip6ad_t
|
||||
{
|
||||
qse_uint8_t value[16];
|
||||
};
|
||||
|
||||
#define QSE_IP4AD_IS_LOOPBACK(addr) ((((addr)->value) & QSE_CONST_HTON32(0xFF000000)) == QSE_CONST_HTON32(0x7F000000))
|
||||
|
||||
#define QSE_IP6AD_IS_LOOPBACK(addr) \
|
||||
((addr)->value[0] == 0 && (addr)->value[1] == 0 && \
|
||||
(addr)->value[2] == 0 && (addr)->value[3] == 0 && \
|
||||
(addr)->value[4] == 0 && (addr)->value[5] == 0 && \
|
||||
(addr)->value[6] == 0 && (addr)->value[7] == 0 && \
|
||||
(addr)->value[8] == 0 && (addr)->value[9] == 0 && \
|
||||
(addr)->value[10] == 0 && (addr)->value[11] == 0 && \
|
||||
(addr)->value[12] == 0 && (addr)->value[13] == 0 && \
|
||||
(addr)->value[14] == 0 && (addr)->value[15] == 1)
|
||||
|
||||
// FE80::/10
|
||||
#define QSE_IP6AD_IS_LINK_LOCAL(addr) (this->value[0] == 0xFE && (this->value[1] & 0xC0) == 0x80)
|
||||
// FEC0::/10
|
||||
#define QSE_IP6AD_IS_SITE_LOCAL(addr) (this->value[0] == 0xFE && (this->value[1] & 0xC0) == 0xC0)
|
||||
|
||||
#define QSE_IP6AD_IS_MULTICAST(addr) ((addr)->value[0] == 0xFF)
|
||||
#define QSE_IP6AD_IS_MULTICAST_LINK_LOCAL(addr) ((addr)->value[0] == 0xFF && ((addr)->value[1] & 0x0F) == 0x02)
|
||||
#define QSE_IP6AD_IS_MULTICAST_SITE_LOCAL(addr) ((addr)->value[0] == 0xFF && ((addr)->value[1] & 0x0F) == 0x05)
|
||||
#define QSE_IP6AD_IS_MULTICAST_ORGANIZATION(addr) ((addr)->value[0] == 0xFF && ((addr)->value[1] & 0x0F) == 0x08)
|
||||
#define QSE_IP6AD_IS_MULTICAST_GLOBAL(addr) ((addr)->value[0] == 0xFF && ((addr)->value[1] & 0x0F) == 0x0E)
|
||||
#define QSE_IP6AD_IS_MULTICAST_INTERFACE_LOCAL(addr) ((addr)->value[0] == 0xFF && ((addr)->value[1] & 0x0F) == 0x01)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
struct qse_ip4adxx_t: public qse_ip4ad_t
|
||||
{
|
||||
@ -111,15 +140,132 @@ struct qse_ip4adxx_t: public qse_ip4ad_t
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
struct qse_ip6adxx_t: public qse_ip6ad_t
|
||||
{
|
||||
struct ad64_t
|
||||
{
|
||||
qse_uint64_t w[2];
|
||||
};
|
||||
|
||||
qse_ip6adxx_t ()
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
x->w[0] = 0;
|
||||
x->w[1] = 0;
|
||||
}
|
||||
|
||||
qse_ip6adxx_t (qse_uint8_t (*value)[16])
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
x->w[0] = ((ad64_t*)value)->w[0];
|
||||
x->w[1] = ((ad64_t*)value)->w[1];
|
||||
}
|
||||
|
||||
qse_ip6adxx_t (qse_uint8_t (&value)[16])
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
x->w[0] = ((ad64_t*)&value)->w[0];
|
||||
x->w[1] = ((ad64_t*)&value)->w[1];
|
||||
}
|
||||
|
||||
bool operator== (const qse_ip4adxx_t& peer) const
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
register ad64_t* y = (ad64_t*)&peer.value;
|
||||
return x->w[0] == y->w[0] && x->w[1] == y->w[1];
|
||||
}
|
||||
|
||||
bool operator!= (const qse_ip4adxx_t& peer) const
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
register ad64_t* y = (ad64_t*)&peer.value;
|
||||
return x->w[0] != y->w[0] || x->w[1] != y->w[1];
|
||||
}
|
||||
|
||||
qse_ip6adxx_t& operator= (const qse_ip6adxx_t& v)
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
x->w[0] = ((ad64_t*)&v)->w[0];
|
||||
x->w[1] = ((ad64_t*)&v)->w[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool isZero() const
|
||||
{
|
||||
register ad64_t* x = (ad64_t*)this->value;
|
||||
return x->w[0] == 0 && x->w[1] == 0;
|
||||
}
|
||||
|
||||
bool isLoopback() const
|
||||
{
|
||||
return QSE_IP6AD_IS_LOOPBACK(this);
|
||||
}
|
||||
|
||||
bool isLinkLocal() const
|
||||
{
|
||||
// FE80::/10
|
||||
return QSE_IP6AD_IS_LINK_LOCAL(this);
|
||||
}
|
||||
|
||||
bool isSiteLocal() const
|
||||
{
|
||||
// FEC0::/10
|
||||
return QSE_IP6AD_IS_SITE_LOCAL(this);
|
||||
}
|
||||
|
||||
// multicast addresses
|
||||
// ff02:: Link Local: spans the same topological region as the corresponding unicast scope, i.e. all nodes on the same LAN.
|
||||
// ff05:: Site local: is intended to span a single site
|
||||
// ff08:: Organization scope: Intended to span multiple sizes within the same organization
|
||||
// ff0e:: Global scope, assigned by IANA.
|
||||
// ff01:: Interface local: Spans only a single interface on a node and is useful only for loopback transmission of multicast.
|
||||
bool isMulticast() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST(this);
|
||||
}
|
||||
|
||||
bool isMulticastLinkLocal() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST_LINK_LOCAL(this);
|
||||
}
|
||||
|
||||
bool isMulticastSiteLocal() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST_SITE_LOCAL(this);
|
||||
}
|
||||
|
||||
bool isMulticastOrganization() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST_ORGANIZATION(this);
|
||||
}
|
||||
|
||||
bool isMulticastGlobal() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST_GLOBAL(this);
|
||||
}
|
||||
|
||||
bool isMulticastInterfaceLocal() const
|
||||
{
|
||||
return QSE_IP6AD_IS_MULTICAST_INTERFACE_LOCAL(this);
|
||||
}
|
||||
|
||||
bool isV4Mapped () const
|
||||
{
|
||||
return this->value[0] == 0x00 && this->value[1] == 0x00 &&
|
||||
this->value[2] == 0x00 && this->value[3] == 0x00 &&
|
||||
this->value[4] == 0x00 && this->value[5] == 0x00 &&
|
||||
this->value[6] == 0x00 && this->value[7] == 0x00 &&
|
||||
this->value[8] == 0x00 && this->value[9] == 0x00 &&
|
||||
this->value[10] == 0xFF && this->value[11] == 0xFF;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
struct qse_ip6ad_t
|
||||
{
|
||||
qse_uint8_t value[16];
|
||||
};
|
||||
#include <qse/unpack.h>
|
||||
|
||||
#define QSE_IP4AD_IN_LOOPBACK(addr) ((((addr)->value) & QSE_CONST_HTON32(0xFF000000)) == QSE_CONST_HTON32(0x7F000000))
|
||||
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
|
@ -1,5 +1,7 @@
|
||||
pkgincludedir = $(includedir)/qse/dhcp
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
dhcpmsg.h
|
||||
dhcpmsg.h \
|
||||
dhcp4msg.h \
|
||||
dhcp6msg.h
|
||||
|
||||
|
@ -340,7 +340,9 @@ top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = \
|
||||
dhcpmsg.h
|
||||
dhcpmsg.h \
|
||||
dhcp4msg.h \
|
||||
dhcp6msg.h
|
||||
|
||||
all: all-am
|
||||
|
||||
|
217
qse/include/qse/dhcp/dhcp4msg.h
Normal file
217
qse/include/qse/dhcp/dhcp4msg.h
Normal file
@ -0,0 +1,217 @@
|
||||
#ifndef _QSE_DHCP_DHCP4MSG_H_
|
||||
#define _QSE_DHCP_DHCP4MSG_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_DHCP4_SERVER_PORT 67
|
||||
#define QSE_DHCP4_CLIENT_PORT 68
|
||||
#define QSE_DHCP4_MAGIC_COOKIE 0x63825363
|
||||
|
||||
/* operation code */
|
||||
enum qse_dhcp4_op_t
|
||||
{
|
||||
QSE_DHCP4_OP_BOOTREQUEST = 1,
|
||||
QSE_DHCP4_OP_BOOTREPLY = 2
|
||||
};
|
||||
|
||||
enum qse_dhcp4_htype_t
|
||||
{
|
||||
QSE_DHCP4_HTYPE_ETHERNET = 1,
|
||||
QSE_DHCP4_HTYPE_IEEE802 = 6,
|
||||
QSE_DHCP4_HTYPE_ARCNET = 7,
|
||||
QSE_DHCP4_HTYPE_APPLETALK = 8,
|
||||
QSE_DHCP4_HTYPE_HDLC = 17,
|
||||
QSE_DHCP4_HTYPE_ATM = 19,
|
||||
QSE_DHCP4_HTYPE_INFINIBAND = 32
|
||||
};
|
||||
|
||||
/* option codes (partial) */
|
||||
enum qse_dhcp4_opt_t
|
||||
{
|
||||
QSE_DHCP4_OPT_PADDING = 0x00,
|
||||
QSE_DHCP4_OPT_SUBNET = 0x01,
|
||||
QSE_DHCP4_OPT_TIME_OFFSET = 0x02,
|
||||
QSE_DHCP4_OPT_ROUTER = 0x03,
|
||||
QSE_DHCP4_OPT_TIME_SERVER = 0x04,
|
||||
QSE_DHCP4_OPT_NAME_SERVER = 0x05,
|
||||
QSE_DHCP4_OPT_DNS_SERVER = 0x06,
|
||||
QSE_DHCP4_OPT_LOG_SERVER = 0x07,
|
||||
QSE_DHCP4_OPT_COOKIE_SERVER = 0x08,
|
||||
QSE_DHCP4_OPT_LPR_SERVER = 0x09,
|
||||
QSE_DHCP4_OPT_HOST_NAME = 0x0c,
|
||||
QSE_DHCP4_OPT_BOOT_SIZE = 0x0d,
|
||||
QSE_DHCP4_OPT_DOMAIN_NAME = 0x0f,
|
||||
QSE_DHCP4_OPT_SWAP_SERVER = 0x10,
|
||||
QSE_DHCP4_OPT_ROOT_PATH = 0x11,
|
||||
QSE_DHCP4_OPT_IP_TTL = 0x17,
|
||||
QSE_DHCP4_OPT_MTU = 0x1a,
|
||||
QSE_DHCP4_OPT_BROADCAST = 0x1c,
|
||||
QSE_DHCP4_OPT_NTP_SERVER = 0x2a,
|
||||
QSE_DHCP4_OPT_WINS_SERVER = 0x2c,
|
||||
QSE_DHCP4_OPT_REQUESTED_IPADDR = 0x32,
|
||||
QSE_DHCP4_OPT_LEASE_TIME = 0x33,
|
||||
QSE_DHCP4_OPT_OVERLOAD = 0x34, /* overload sname or file */
|
||||
QSE_DHCP4_OPT_MESSAGE_TYPE = 0x35,
|
||||
QSE_DHCP4_OPT_SERVER_ID = 0x36,
|
||||
QSE_DHCP4_OPT_PARAM_REQ = 0x37,
|
||||
QSE_DHCP4_OPT_MESSAGE = 0x38,
|
||||
QSE_DHCP4_OPT_MAX_SIZE = 0x39,
|
||||
QSE_DHCP4_OPT_T1 = 0x3a,
|
||||
QSE_DHCP4_OPT_T2 = 0x3b,
|
||||
QSE_DHCP4_OPT_VENDOR = 0x3c,
|
||||
QSE_DHCP4_OPT_CLIENT_ID = 0x3d,
|
||||
QSE_DHCP4_OPT_RELAY = 0x52,
|
||||
QSE_DHCP4_OPT_SUBNET_SELECTION = 0x76,
|
||||
QSE_DHCP4_OPT_END = 0xFF
|
||||
};
|
||||
|
||||
/* flags for QSE_DHCP4_OPT_OVERLOAD */
|
||||
enum qse_dhcp4_opt_overload_t
|
||||
{
|
||||
QSE_DHCP4_OPT_OVERLOAD_FILE = (1 << 0),
|
||||
QSE_DHCP4_OPT_OVERLOAD_SNAME = (1 << 1)
|
||||
};
|
||||
|
||||
/* flags for QSE_DHCP4_OPT_OVERLOAD */
|
||||
enum qse_dhcp4_opt_relay_t
|
||||
{
|
||||
QSE_DHCP4_OPT_RELAY_CIRCUIT_ID = 1,
|
||||
QSE_DHCP4_OPT_RELAY_REMOTE_ID = 2
|
||||
};
|
||||
|
||||
/* message type */
|
||||
enum qse_dhcp4_msg_t
|
||||
{
|
||||
QSE_DHCP4_MSG_DISCOVER = 1,
|
||||
QSE_DHCP4_MSG_OFFER = 2,
|
||||
QSE_DHCP4_MSG_REQUEST = 3,
|
||||
QSE_DHCP4_MSG_DECLINE = 4,
|
||||
QSE_DHCP4_MSG_ACK = 5,
|
||||
QSE_DHCP4_MSG_NAK = 6,
|
||||
QSE_DHCP4_MSG_RELEASE = 7,
|
||||
QSE_DHCP4_MSG_INFORM = 8,
|
||||
|
||||
/*QSE_DHCP4_MSG_RENEW = 9,*/
|
||||
|
||||
QSE_DHCP4_MSG_LEASE_QUERY = 10,
|
||||
QSE_DHCP4_MSG_LEASE_UNASSIGNED = 11,
|
||||
QSE_DHCP4_MSG_LEASE_UNKNOWN = 12,
|
||||
QSE_DHCP4_MSG_LEASE_ACTIVE = 13,
|
||||
|
||||
QSE_DHCP4_MSG_BULK_LEASE_QUERY = 14,
|
||||
QSE_DHCP4_MSG_LEASE_QUERY_DONE = 15
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
#include <qse/pack1.h>
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
struct qse_dhcp4_pkt_hdr_t
|
||||
{
|
||||
qse_uint8_t op;
|
||||
qse_uint8_t htype;
|
||||
qse_uint8_t hlen;
|
||||
qse_uint8_t hops;
|
||||
qse_uint32_t xid; /* transaction id */
|
||||
qse_uint16_t secs; /* seconds elapsed */
|
||||
qse_uint16_t flags; /* bootp flags */
|
||||
qse_uint32_t ciaddr; /* client ip */
|
||||
qse_uint32_t yiaddr; /* your ip */
|
||||
qse_uint32_t siaddr; /* next server ip */
|
||||
qse_uint32_t giaddr; /* relay agent ip */
|
||||
qse_uint8_t chaddr[16]; /* client mac */
|
||||
|
||||
char sname[64]; /* server host name */
|
||||
char file[128]; /* boot file name */
|
||||
|
||||
/* options are placed after the header.
|
||||
* the first four bytes of the options compose a magic cookie
|
||||
* 0x63 0x82 0x53 0x63 */
|
||||
};
|
||||
typedef struct qse_dhcp4_pkt_hdr_t qse_dhcp4_pkt_hdr_t;
|
||||
|
||||
struct qse_dhcp4_opt_hdr_t
|
||||
{
|
||||
qse_uint8_t code;
|
||||
qse_uint8_t len;
|
||||
};
|
||||
typedef struct qse_dhcp4_opt_hdr_t qse_dhcp4_opt_hdr_t;
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
#include <qse/unpack.h>
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
typedef int (*qse_dhcp4_opt_walker_t) (qse_dhcp4_opt_hdr_t* opt);
|
||||
|
||||
struct qse_dhcp4_pktinf_t
|
||||
{
|
||||
qse_dhcp4_pkt_hdr_t* hdr;
|
||||
qse_size_t len;
|
||||
};
|
||||
typedef struct qse_dhcp4_pktinf_t qse_dhcp4_pktinf_t;
|
||||
|
||||
struct qse_dhcp4_pktbuf_t
|
||||
{
|
||||
qse_dhcp4_pkt_hdr_t* hdr;
|
||||
qse_size_t len;
|
||||
qse_size_t capa;
|
||||
};
|
||||
typedef struct qse_dhcp4_pktbuf_t qse_dhcp4_pktbuf_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_initialize_pktbuf (
|
||||
qse_dhcp4_pktbuf_t* pkt,
|
||||
void* buf,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_add_option (
|
||||
qse_dhcp4_pktbuf_t* pkt,
|
||||
int code,
|
||||
void* optr, /**< option data pointer */
|
||||
qse_uint8_t olen /**< option data length */
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_dhcp4_compact_options (
|
||||
qse_dhcp4_pktbuf_t* pkt
|
||||
);
|
||||
|
||||
#if 0
|
||||
QSE_EXPORT int qse_dhcp4_add_options (
|
||||
qse_dhcp4_pkt_hdr_t* pkt,
|
||||
qse_size_t len,
|
||||
qse_size_t max,
|
||||
int code,
|
||||
qse_uint8_t* optr, /* option data */
|
||||
qse_uint8_t olen /* option length */
|
||||
);
|
||||
#endif
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_walk_options (
|
||||
const qse_dhcp4_pktinf_t* pkt,
|
||||
qse_dhcp4_opt_walker_t walker
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_dhcp4_opt_hdr_t* qse_dhcp4_find_option (
|
||||
const qse_dhcp4_pktinf_t* pkt,
|
||||
int code
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_uint8_t* qse_dhcp4_get_relay_suboption (
|
||||
const qse_uint8_t* ptr,
|
||||
qse_uint8_t len,
|
||||
int code,
|
||||
qse_uint8_t* olen
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
88
qse/include/qse/dhcp/dhcp6msg.h
Normal file
88
qse/include/qse/dhcp/dhcp6msg.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef _QSE_DHCP_DHCP6MSG_H_
|
||||
#define _QSE_DHCP_DHCP6MSG_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_DHCP6_SERVER_PORT 547
|
||||
#define QSE_DHCP6_CLIENT_PORT 546
|
||||
#define QSE_DHCP6_HOP_COUNT_LIMIT 32
|
||||
|
||||
enum qse_dhcp6_msg_t
|
||||
{
|
||||
QSE_DHCP6_MSG_SOLICIT = 1,
|
||||
QSE_DHCP6_MSG_ADVERTISE = 2,
|
||||
QSE_DHCP6_MSG_REQUEST = 3,
|
||||
QSE_DHCP6_MSG_CONFIRM = 4,
|
||||
QSE_DHCP6_MSG_RENEW = 5,
|
||||
QSE_DHCP6_MSG_REBIND = 6,
|
||||
QSE_DHCP6_MSG_REPLY = 7,
|
||||
QSE_DHCP6_MSG_RELEASE = 8,
|
||||
QSE_DHCP6_MSG_DECLINE = 9,
|
||||
QSE_DHCP6_MSG_RECONFIGURE = 10,
|
||||
QSE_DHCP6_MSG_INFOREQ = 11,
|
||||
QSE_DHCP6_MSG_RELAYFORW = 12,
|
||||
QSE_DHCP6_MSG_RELAYREPL = 13,
|
||||
};
|
||||
typedef enum qse_dhcp6_msg_t qse_dhcp6_msg_t;
|
||||
|
||||
enum qse_dhcp6_opt_t
|
||||
{
|
||||
QSE_DHCP6_OPT_RELAY_MESSAGE = 9,
|
||||
QSE_DHCP6_OPT_INTERFACE_ID = 18
|
||||
};
|
||||
typedef enum qse_dhcp6_opt_t qse_dhcp6_opt_t;
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
#include <qse/pack1.h>
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
struct qse_dhcp6_pkt_hdr_t
|
||||
{
|
||||
qse_uint8_t msgtype;
|
||||
qse_uint8_t transid[3];
|
||||
};
|
||||
typedef struct qse_dhcp6_pkt_hdr_t qse_dhcp6_pkt_hdr_t;
|
||||
|
||||
struct qse_dhcp6_relay_hdr_t
|
||||
{
|
||||
qse_uint8_t msgtype; /* RELAY-FORW, RELAY-REPL */
|
||||
qse_uint8_t hopcount;
|
||||
qse_uint8_t linkaddr[16];
|
||||
qse_uint8_t peeraddr[16];
|
||||
};
|
||||
typedef struct qse_dhcp6_relay_hdr_t qse_dhcp6_relay_hdr_t;
|
||||
|
||||
struct qse_dhcp6_opt_hdr_t
|
||||
{
|
||||
qse_uint16_t code;
|
||||
qse_uint16_t len; /* length of option data, excludes the option header */
|
||||
};
|
||||
typedef struct qse_dhcp6_opt_hdr_t qse_dhcp6_opt_hdr_t;
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
#include <qse/unpack.h>
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
struct qse_dhcp6_pktinf_t
|
||||
{
|
||||
qse_dhcp6_pkt_hdr_t* hdr;
|
||||
qse_size_t len;
|
||||
};
|
||||
typedef struct qse_dhcp6_pktinf_t qse_dhcp6_pktinf_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT qse_dhcp6_opt_hdr_t* qse_dhcp6_find_option (
|
||||
const qse_dhcp6_pktinf_t* pkt,
|
||||
int code
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,210 +1,7 @@
|
||||
#ifndef _QSE_DHCP_DHCPMSG_H_
|
||||
#define _QSE_DHCP_DHCPMSG_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/dhcp/dhcp4msg.h>
|
||||
#include <qse/dhcp/dhcp6msg.h>
|
||||
|
||||
#define QSE_DHCP4_SERVER_PORT 67
|
||||
#define QSE_DHCP4_CLIENT_PORT 68
|
||||
#define QSE_DHCP4_MAGIC_COOKIE 0x63825363
|
||||
|
||||
/* operation code */
|
||||
enum qse_dhcp4_op_t
|
||||
{
|
||||
QSE_DHCP4_OP_BOOTREQUEST = 1,
|
||||
QSE_DHCP4_OP_BOOTREPLY = 2
|
||||
};
|
||||
|
||||
enum qse_dhcp4_htype_t
|
||||
{
|
||||
QSE_DHCP4_HTYPE_ETHERNET = 1,
|
||||
QSE_DHCP4_HTYPE_IEEE802 = 6,
|
||||
QSE_DHCP4_HTYPE_ARCNET = 7,
|
||||
QSE_DHCP4_HTYPE_APPLETALK = 8,
|
||||
QSE_DHCP4_HTYPE_HDLC = 17,
|
||||
QSE_DHCP4_HTYPE_ATM = 19,
|
||||
QSE_DHCP4_HTYPE_INFINIBAND = 32
|
||||
};
|
||||
|
||||
/* option codes (partial) */
|
||||
enum qse_dhcp4_opt_t
|
||||
{
|
||||
QSE_DHCP4_OPT_PADDING = 0x00,
|
||||
QSE_DHCP4_OPT_SUBNET = 0x01,
|
||||
QSE_DHCP4_OPT_TIME_OFFSET = 0x02,
|
||||
QSE_DHCP4_OPT_ROUTER = 0x03,
|
||||
QSE_DHCP4_OPT_TIME_SERVER = 0x04,
|
||||
QSE_DHCP4_OPT_NAME_SERVER = 0x05,
|
||||
QSE_DHCP4_OPT_DNS_SERVER = 0x06,
|
||||
QSE_DHCP4_OPT_LOG_SERVER = 0x07,
|
||||
QSE_DHCP4_OPT_COOKIE_SERVER = 0x08,
|
||||
QSE_DHCP4_OPT_LPR_SERVER = 0x09,
|
||||
QSE_DHCP4_OPT_HOST_NAME = 0x0c,
|
||||
QSE_DHCP4_OPT_BOOT_SIZE = 0x0d,
|
||||
QSE_DHCP4_OPT_DOMAIN_NAME = 0x0f,
|
||||
QSE_DHCP4_OPT_SWAP_SERVER = 0x10,
|
||||
QSE_DHCP4_OPT_ROOT_PATH = 0x11,
|
||||
QSE_DHCP4_OPT_IP_TTL = 0x17,
|
||||
QSE_DHCP4_OPT_MTU = 0x1a,
|
||||
QSE_DHCP4_OPT_BROADCAST = 0x1c,
|
||||
QSE_DHCP4_OPT_NTP_SERVER = 0x2a,
|
||||
QSE_DHCP4_OPT_WINS_SERVER = 0x2c,
|
||||
QSE_DHCP4_OPT_REQUESTED_IPADDR = 0x32,
|
||||
QSE_DHCP4_OPT_LEASE_TIME = 0x33,
|
||||
QSE_DHCP4_OPT_OVERLOAD = 0x34, /* overload sname or file */
|
||||
QSE_DHCP4_OPT_MESSAGE_TYPE = 0x35,
|
||||
QSE_DHCP4_OPT_SERVER_ID = 0x36,
|
||||
QSE_DHCP4_OPT_PARAM_REQ = 0x37,
|
||||
QSE_DHCP4_OPT_MESSAGE = 0x38,
|
||||
QSE_DHCP4_OPT_MAX_SIZE = 0x39,
|
||||
QSE_DHCP4_OPT_T1 = 0x3a,
|
||||
QSE_DHCP4_OPT_T2 = 0x3b,
|
||||
QSE_DHCP4_OPT_VENDOR = 0x3c,
|
||||
QSE_DHCP4_OPT_CLIENT_ID = 0x3d,
|
||||
QSE_DHCP4_OPT_RELAY = 0x52,
|
||||
QSE_DHCP4_OPT_SUBNET_SELECTION = 0x76,
|
||||
QSE_DHCP4_OPT_END = 0xFF
|
||||
};
|
||||
|
||||
/* flags for QSE_DHCP4_OPT_OVERLOAD */
|
||||
enum qse_dhcp4_opt_overload_t
|
||||
{
|
||||
QSE_DHCP4_OPT_OVERLOAD_FILE = (1 << 0),
|
||||
QSE_DHCP4_OPT_OVERLOAD_SNAME = (1 << 1)
|
||||
};
|
||||
|
||||
/* flags for QSE_DHCP4_OPT_OVERLOAD */
|
||||
enum qse_dhcp4_opt_relay_t
|
||||
{
|
||||
QSE_DHCP4_OPT_RELAY_CIRCUIT_ID = 1,
|
||||
QSE_DHCP4_OPT_RELAY_REMOTE_ID = 2
|
||||
};
|
||||
|
||||
/* message type */
|
||||
enum qse_dhcp4_msg_t
|
||||
{
|
||||
QSE_DHCP4_MSG_DISCOVER = 1,
|
||||
QSE_DHCP4_MSG_OFFER = 2,
|
||||
QSE_DHCP4_MSG_REQUEST = 3,
|
||||
QSE_DHCP4_MSG_DECLINE = 4,
|
||||
QSE_DHCP4_MSG_ACK = 5,
|
||||
QSE_DHCP4_MSG_NAK = 6,
|
||||
QSE_DHCP4_MSG_RELEASE = 7,
|
||||
QSE_DHCP4_MSG_INFORM = 8,
|
||||
|
||||
/*QSE_DHCP4_MSG_RENEW = 9,*/
|
||||
|
||||
QSE_DHCP4_MSG_LEASE_QUERY = 10,
|
||||
QSE_DHCP4_MSG_LEASE_UNASSIGNED = 11,
|
||||
QSE_DHCP4_MSG_LEASE_UNKNOWN = 12,
|
||||
QSE_DHCP4_MSG_LEASE_ACTIVE = 13,
|
||||
|
||||
QSE_DHCP4_MSG_BULK_LEASE_QUERY = 14,
|
||||
QSE_DHCP4_MSG_LEASE_QUERY_DONE = 15
|
||||
};
|
||||
|
||||
#include <qse/pack1.h>
|
||||
|
||||
struct qse_dhcp4_pkt_hdr_t
|
||||
{
|
||||
qse_uint8_t op;
|
||||
qse_uint8_t htype;
|
||||
qse_uint8_t hlen;
|
||||
qse_uint8_t hops;
|
||||
qse_uint32_t xid; /* transaction id */
|
||||
qse_uint16_t secs; /* seconds elapsed */
|
||||
qse_uint16_t flags; /* bootp flags */
|
||||
qse_uint32_t ciaddr; /* client ip */
|
||||
qse_uint32_t yiaddr; /* your ip */
|
||||
qse_uint32_t siaddr; /* next server ip */
|
||||
qse_uint32_t giaddr; /* relay agent ip */
|
||||
qse_uint8_t chaddr[16]; /* client mac */
|
||||
|
||||
char sname[64]; /* server host name */
|
||||
char file[128]; /* boot file name */
|
||||
|
||||
/* options are placed after the header.
|
||||
* the first four bytes of the options compose a magic cookie
|
||||
* 0x63 0x82 0x53 0x63 */
|
||||
};
|
||||
typedef struct qse_dhcp4_pkt_hdr_t qse_dhcp4_pkt_hdr_t;
|
||||
|
||||
struct qse_dhcp4_opt_hdr_t
|
||||
{
|
||||
qse_uint8_t code;
|
||||
qse_uint8_t len;
|
||||
};
|
||||
typedef struct qse_dhcp4_opt_hdr_t qse_dhcp4_opt_hdr_t;
|
||||
|
||||
typedef int (*qse_dhcp4_opt_walker_t) (qse_dhcp4_opt_hdr_t* opt);
|
||||
|
||||
struct qse_dhcp4_pktinf_t
|
||||
{
|
||||
qse_dhcp4_pkt_hdr_t* hdr;
|
||||
qse_size_t len;
|
||||
};
|
||||
typedef struct qse_dhcp4_pktinf_t qse_dhcp4_pktinf_t;
|
||||
|
||||
struct qse_dhcp4_pktbuf_t
|
||||
{
|
||||
qse_dhcp4_pkt_hdr_t* hdr;
|
||||
qse_size_t len;
|
||||
qse_size_t capa;
|
||||
};
|
||||
typedef struct qse_dhcp4_pktbuf_t qse_dhcp4_pktbuf_t;
|
||||
|
||||
#include <qse/unpack.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_initialize_pktbuf (
|
||||
qse_dhcp4_pktbuf_t* pkt,
|
||||
void* buf,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_add_option (
|
||||
qse_dhcp4_pktbuf_t* pkt,
|
||||
int code,
|
||||
void* optr, /**< option data pointer */
|
||||
qse_uint8_t olen /**< option data length */
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_dhcp4_compact_options (
|
||||
qse_dhcp4_pktbuf_t* pkt
|
||||
);
|
||||
|
||||
#if 0
|
||||
QSE_EXPORT int qse_dhcp4_add_options (
|
||||
qse_dhcp4_pkt_hdr_t* pkt,
|
||||
qse_size_t len,
|
||||
qse_size_t max,
|
||||
int code,
|
||||
qse_uint8_t* optr, /* option data */
|
||||
qse_uint8_t olen /* option length */
|
||||
);
|
||||
#endif
|
||||
|
||||
QSE_EXPORT int qse_dhcp4_walk_options (
|
||||
const qse_dhcp4_pktinf_t* pkt,
|
||||
qse_dhcp4_opt_walker_t walker
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_dhcp4_opt_hdr_t* qse_dhcp4_find_option (
|
||||
const qse_dhcp4_pktinf_t* pkt,
|
||||
int code
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_uint8_t* qse_dhcp4_get_relay_suboption (
|
||||
const qse_uint8_t* ptr,
|
||||
qse_uint8_t len,
|
||||
int code,
|
||||
qse_uint8_t* olen
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@ AM_CPPFLAGS = \
|
||||
|
||||
lib_LTLIBRARIES = libqsedhcp.la
|
||||
libqsedhcp_la_SOURCES = \
|
||||
dhcpmsg.c
|
||||
dhcp4msg.c dhcp6msg.c
|
||||
|
||||
libqsedhcp_la_CFLAGS =
|
||||
libqsedhcp_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
||||
|
@ -134,7 +134,8 @@ am__uninstall_files_from_dir = { \
|
||||
am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libqsedhcp_la_DEPENDENCIES =
|
||||
am_libqsedhcp_la_OBJECTS = libqsedhcp_la-dhcpmsg.lo
|
||||
am_libqsedhcp_la_OBJECTS = libqsedhcp_la-dhcp4msg.lo \
|
||||
libqsedhcp_la-dhcp6msg.lo
|
||||
libqsedhcp_la_OBJECTS = $(am_libqsedhcp_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
@ -379,7 +380,7 @@ AM_CPPFLAGS = \
|
||||
#noinst_HEADERS =
|
||||
lib_LTLIBRARIES = libqsedhcp.la
|
||||
libqsedhcp_la_SOURCES = \
|
||||
dhcpmsg.c
|
||||
dhcp4msg.c dhcp6msg.c
|
||||
|
||||
libqsedhcp_la_CFLAGS =
|
||||
libqsedhcp_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
||||
@ -462,7 +463,8 @@ mostlyclean-compile:
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsedhcp_la-dhcpmsg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsedhcp_la-dhcp4msg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsedhcp_la-dhcp6msg.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@ -485,12 +487,19 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
libqsedhcp_la-dhcpmsg.lo: dhcpmsg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -MT libqsedhcp_la-dhcpmsg.lo -MD -MP -MF $(DEPDIR)/libqsedhcp_la-dhcpmsg.Tpo -c -o libqsedhcp_la-dhcpmsg.lo `test -f 'dhcpmsg.c' || echo '$(srcdir)/'`dhcpmsg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqsedhcp_la-dhcpmsg.Tpo $(DEPDIR)/libqsedhcp_la-dhcpmsg.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dhcpmsg.c' object='libqsedhcp_la-dhcpmsg.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
libqsedhcp_la-dhcp4msg.lo: dhcp4msg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -MT libqsedhcp_la-dhcp4msg.lo -MD -MP -MF $(DEPDIR)/libqsedhcp_la-dhcp4msg.Tpo -c -o libqsedhcp_la-dhcp4msg.lo `test -f 'dhcp4msg.c' || echo '$(srcdir)/'`dhcp4msg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqsedhcp_la-dhcp4msg.Tpo $(DEPDIR)/libqsedhcp_la-dhcp4msg.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dhcp4msg.c' object='libqsedhcp_la-dhcp4msg.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -c -o libqsedhcp_la-dhcpmsg.lo `test -f 'dhcpmsg.c' || echo '$(srcdir)/'`dhcpmsg.c
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -c -o libqsedhcp_la-dhcp4msg.lo `test -f 'dhcp4msg.c' || echo '$(srcdir)/'`dhcp4msg.c
|
||||
|
||||
libqsedhcp_la-dhcp6msg.lo: dhcp6msg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -MT libqsedhcp_la-dhcp6msg.lo -MD -MP -MF $(DEPDIR)/libqsedhcp_la-dhcp6msg.Tpo -c -o libqsedhcp_la-dhcp6msg.lo `test -f 'dhcp6msg.c' || echo '$(srcdir)/'`dhcp6msg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqsedhcp_la-dhcp6msg.Tpo $(DEPDIR)/libqsedhcp_la-dhcp6msg.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dhcp6msg.c' object='libqsedhcp_la-dhcp6msg.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsedhcp_la_CFLAGS) $(CFLAGS) -c -o libqsedhcp_la-dhcp6msg.lo `test -f 'dhcp6msg.c' || echo '$(srcdir)/'`dhcp6msg.c
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
31
qse/lib/dhcp/dhcp6msg.c
Normal file
31
qse/lib/dhcp/dhcp6msg.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <qse/dhcp/dhcp6msg.h>
|
||||
#include <qse/cmn/hton.h>
|
||||
|
||||
qse_dhcp6_opt_hdr_t* qse_dhcp6_find_option (const qse_dhcp6_pktinf_t* pkt, int code)
|
||||
{
|
||||
qse_dhcp6_opt_hdr_t* opt;
|
||||
qse_size_t rem;
|
||||
|
||||
if (pkt->len < QSE_SIZEOF(qse_dhcp6_pkt_hdr_t)) return QSE_NULL;
|
||||
|
||||
if (pkt->hdr->msgtype == QSE_DHCP6_MSG_RELAYFORW || pkt->hdr->msgtype == QSE_DHCP6_MSG_RELAYREPL)
|
||||
{
|
||||
if (pkt->len < QSE_SIZEOF(qse_dhcp6_relay_hdr_t)) return QSE_NULL;
|
||||
|
||||
rem = pkt->len - QSE_SIZEOF(qse_dhcp6_relay_hdr_t);
|
||||
opt = (qse_dhcp6_opt_hdr_t*)(((qse_dhcp6_relay_hdr_t*)pkt->hdr) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
rem = pkt->len - QSE_SIZEOF(qse_dhcp6_pkt_hdr_t);
|
||||
opt = (qse_dhcp6_opt_hdr_t*)(pkt->hdr + 1);
|
||||
}
|
||||
|
||||
while (rem >= QSE_SIZEOF(qse_dhcp6_opt_hdr_t))
|
||||
{
|
||||
if (qse_ntoh16(opt->code) == code) return opt;
|
||||
rem -= QSE_SIZEOF(qse_dhcp6_opt_hdr_t) + qse_ntoh16(opt->len);
|
||||
}
|
||||
|
||||
return QSE_NULL;
|
||||
}
|
Loading…
Reference in New Issue
Block a user