2008-05-06 08:33:42 +04:00
|
|
|
#ifndef _IFCONFIG_PARSE_H
|
|
|
|
#define _IFCONFIG_PARSE_H
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
#include <stdbool.h>
|
2008-08-02 02:29:13 +04:00
|
|
|
#include <stddef.h>
|
2008-05-06 08:33:42 +04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <prop/proplib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
struct match;
|
|
|
|
struct parser;
|
|
|
|
|
|
|
|
extern struct pbranch command_root;
|
|
|
|
|
|
|
|
typedef int (*parser_exec_t)(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
typedef int (*parser_match_t)(const struct parser *, const struct match *,
|
|
|
|
struct match *, int, const char *);
|
|
|
|
typedef int (*parser_init_t)(struct parser *);
|
|
|
|
|
|
|
|
struct match {
|
|
|
|
prop_dictionary_t m_env;
|
|
|
|
const struct parser *m_nextparser;
|
|
|
|
const struct parser *m_parser;
|
|
|
|
int m_argidx;
|
|
|
|
parser_exec_t m_exec;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* method table */
|
|
|
|
struct parser_methods {
|
|
|
|
parser_match_t pm_match;
|
|
|
|
parser_init_t pm_init;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct parser {
|
|
|
|
const struct parser_methods *p_methods;
|
|
|
|
parser_exec_t p_exec;
|
|
|
|
const char *p_name;
|
|
|
|
struct parser *p_nextparser;
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
bool p_initialized;
|
2008-05-06 08:33:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct branch {
|
|
|
|
SIMPLEQ_ENTRY(branch) b_next;
|
|
|
|
struct parser *b_nextparser;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pbranch {
|
|
|
|
struct parser pb_parser;
|
|
|
|
SIMPLEQ_HEAD(, branch) pb_branches;
|
|
|
|
bool pb_match_first;
|
|
|
|
const struct branch *pb_brinit;
|
|
|
|
size_t pb_nbrinit;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pterm {
|
|
|
|
struct parser pt_parser;
|
|
|
|
const char *pt_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct parser_methods paddr_methods;
|
|
|
|
extern const struct parser_methods pbranch_methods;
|
|
|
|
extern const struct parser_methods piface_methods;
|
|
|
|
extern const struct parser_methods pinteger_methods;
|
|
|
|
extern const struct parser_methods pstr_methods;
|
|
|
|
extern const struct parser_methods pkw_methods;
|
|
|
|
extern const struct parser_methods pterm_methods;
|
|
|
|
|
|
|
|
#define PTERM_INITIALIZER(__pt, __name, __exec, __key) \
|
|
|
|
{ \
|
|
|
|
.pt_parser = {.p_name = (__name), .p_methods = &pterm_methods, \
|
|
|
|
.p_exec = (__exec)}, \
|
|
|
|
.pt_key = (__key) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PBRANCH_INITIALIZER(__pb, __name, __brs, __nbr, __match_first) \
|
|
|
|
{ \
|
|
|
|
.pb_parser = {.p_name = (__name), .p_methods = &pbranch_methods},\
|
|
|
|
.pb_branches = SIMPLEQ_HEAD_INITIALIZER((__pb)->pb_branches), \
|
|
|
|
.pb_brinit = (__brs), \
|
|
|
|
.pb_nbrinit = (__nbr), \
|
|
|
|
.pb_match_first = (__match_first) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PSTR_INITIALIZER(__ps, __name, __defexec, __defkey, __defnext) \
|
|
|
|
{ \
|
|
|
|
.ps_parser = {.p_name = (__name), .p_methods = &pstr_methods, \
|
|
|
|
.p_exec = (__defexec), \
|
|
|
|
.p_nextparser = (__defnext)}, \
|
|
|
|
.ps_key = (__defkey) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PADDR_INITIALIZER(__pa, __name, __defexec, __addrkey, \
|
|
|
|
__maskkey, __activator, __deactivator, __defnext) \
|
|
|
|
{ \
|
|
|
|
.pa_parser = {.p_name = (__name), .p_methods = &paddr_methods, \
|
|
|
|
.p_exec = (__defexec), \
|
|
|
|
.p_nextparser = (__defnext)}, \
|
|
|
|
.pa_addrkey = (__addrkey), \
|
|
|
|
.pa_maskkey = (__maskkey), \
|
|
|
|
.pa_activator = (__activator), \
|
|
|
|
.pa_deactivator = (__deactivator), \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PIFACE_INITIALIZER(__pif, __name, __defexec, __defkey, __defnext)\
|
|
|
|
{ \
|
|
|
|
.pif_parser = {.p_name = (__name), .p_methods = &piface_methods,\
|
|
|
|
.p_exec = (__defexec), \
|
|
|
|
.p_nextparser = (__defnext)}, \
|
|
|
|
.pif_key = (__defkey) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PINTEGER_INITIALIZER1(__pi, __name, __min, __max, __base, \
|
|
|
|
__defexec, __defkey, __defnext) \
|
|
|
|
{ \
|
|
|
|
.pi_parser = {.p_name = (__name), .p_methods = &pinteger_methods,\
|
|
|
|
.p_exec = (__defexec), \
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
.p_nextparser = (__defnext), \
|
|
|
|
.p_initialized = false}, \
|
2008-05-06 08:33:42 +04:00
|
|
|
.pi_min = (__min), \
|
|
|
|
.pi_max = (__max), \
|
|
|
|
.pi_base = (__base), \
|
|
|
|
.pi_key = (__defkey) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PINTEGER_INITIALIZER(__pi, __name, __base, __defexec, __defkey, \
|
|
|
|
__defnext) \
|
|
|
|
PINTEGER_INITIALIZER1(__pi, __name, INTMAX_MIN, INTMAX_MAX, \
|
|
|
|
__base, __defexec, __defkey, __defnext)
|
|
|
|
|
|
|
|
#define PKW_INITIALIZER(__pk, __name, __defexec, __defkey, __kws, __nkw,\
|
|
|
|
__defnext) \
|
|
|
|
{ \
|
|
|
|
.pk_parser = {.p_name = (__name), \
|
|
|
|
.p_exec = (__defexec), \
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
.p_methods = &pkw_methods, \
|
|
|
|
.p_initialized = false}, \
|
2008-05-06 08:33:42 +04:00
|
|
|
.pk_keywords = SIMPLEQ_HEAD_INITIALIZER((__pk)->pk_keywords), \
|
|
|
|
.pk_kwinit = (__kws), \
|
|
|
|
.pk_nkwinit = (__nkw), \
|
|
|
|
.pk_keyinit = (__defkey), \
|
|
|
|
.pk_nextinit = (__defnext) \
|
|
|
|
}
|
|
|
|
|
2008-05-08 01:29:27 +04:00
|
|
|
#define IFKW(__word, __flag) \
|
|
|
|
{ \
|
2008-05-19 22:00:31 +04:00
|
|
|
.k_word = (__word), .k_neg = true, .k_type = KW_T_INT, \
|
|
|
|
.k_int = (__flag), \
|
|
|
|
.k_negint = -(__flag) \
|
2008-05-08 01:29:27 +04:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#define KW_T_NONE 0
|
|
|
|
#define KW_T_OBJ 1
|
2008-05-19 22:00:31 +04:00
|
|
|
#define KW_T_INT 2
|
2008-05-06 08:33:42 +04:00
|
|
|
#define KW_T_STR 3
|
|
|
|
#define KW_T_BOOL 4
|
2008-05-19 22:00:31 +04:00
|
|
|
#define KW_T_UINT 5
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
struct kwinst {
|
|
|
|
SIMPLEQ_ENTRY(kwinst) k_next;
|
|
|
|
int k_type;
|
|
|
|
const char *k_word;
|
|
|
|
const char *k_key;
|
|
|
|
const char *k_act;
|
|
|
|
const char *k_deact;
|
|
|
|
const char *k_altdeact;
|
|
|
|
parser_exec_t k_exec;
|
|
|
|
union kwval {
|
2008-05-19 22:00:31 +04:00
|
|
|
int64_t u_sint;
|
|
|
|
uint64_t u_uint;
|
2008-05-06 08:33:42 +04:00
|
|
|
const char *u_str;
|
|
|
|
prop_object_t u_obj;
|
|
|
|
bool u_bool;
|
|
|
|
} k_u, k_negu;
|
2008-05-19 22:00:31 +04:00
|
|
|
#define k_int k_u.u_sint
|
|
|
|
#define k_uint k_u.u_uint
|
2008-05-06 08:33:42 +04:00
|
|
|
#define k_str k_u.u_str
|
|
|
|
#define k_obj k_u.u_obj
|
|
|
|
#define k_bool k_u.u_bool
|
|
|
|
|
2008-05-19 22:00:31 +04:00
|
|
|
#define k_negint k_negu.u_sint
|
|
|
|
#define k_neguint k_negu.u_uint
|
2008-05-06 08:33:42 +04:00
|
|
|
#define k_negstr k_negu.u_str
|
|
|
|
#define k_negobj k_negu.u_obj
|
|
|
|
#define k_negbool k_negu.u_bool
|
|
|
|
|
|
|
|
bool k_neg; /* allow negative form, -keyword */
|
|
|
|
struct parser *k_nextparser;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pkw {
|
|
|
|
struct parser pk_parser;
|
|
|
|
const char *pk_key;
|
|
|
|
const char *pk_keyinit;
|
|
|
|
const struct kwinst *pk_kwinit;
|
|
|
|
size_t pk_nkwinit;
|
|
|
|
SIMPLEQ_HEAD(, kwinst) pk_keywords;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define pk_nextinit pk_parser.p_nextparser
|
|
|
|
#define pk_execinit pk_parser.p_exec
|
|
|
|
|
|
|
|
struct pstr {
|
|
|
|
struct parser ps_parser;
|
|
|
|
const char *ps_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pinteger {
|
|
|
|
struct parser pi_parser;
|
|
|
|
int64_t pi_min;
|
|
|
|
int64_t pi_max;
|
|
|
|
int pi_base;
|
|
|
|
const char *pi_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct intrange {
|
|
|
|
SIMPLEQ_ENTRY(intrange) r_next;
|
|
|
|
int64_t r_bottom;
|
|
|
|
int64_t r_top;
|
|
|
|
struct parser *r_nextparser;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pranges {
|
|
|
|
struct parser pr_parser;
|
|
|
|
SIMPLEQ_HEAD(, intrange) pr_ranges;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct paddr_prefix {
|
2008-05-07 22:08:30 +04:00
|
|
|
int16_t pfx_len;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct sockaddr pfx_addr;
|
|
|
|
};
|
|
|
|
|
2008-08-02 02:29:13 +04:00
|
|
|
static inline size_t
|
|
|
|
paddr_prefix_size(const struct paddr_prefix *pfx)
|
|
|
|
{
|
|
|
|
return offsetof(struct paddr_prefix, pfx_addr) + pfx->pfx_addr.sa_len;
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
struct paddr {
|
|
|
|
struct parser pa_parser;
|
|
|
|
const char *pa_addrkey;
|
|
|
|
const char *pa_maskkey;
|
|
|
|
const char *pa_activator;
|
|
|
|
const char *pa_deactivator;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct piface {
|
|
|
|
struct parser pif_parser;
|
|
|
|
const char *pif_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct prest {
|
|
|
|
struct parser pr_parser;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct prest *prest_create(const char *);
|
|
|
|
struct paddr *paddr_create(const char *, parser_exec_t, const char *,
|
|
|
|
const char *, struct parser *);
|
|
|
|
struct pstr *pstr_create(const char *, parser_exec_t, const char *,
|
|
|
|
struct parser *);
|
|
|
|
struct piface *piface_create(const char *, parser_exec_t, const char *,
|
|
|
|
struct parser *);
|
|
|
|
struct pkw *pkw_create(const char *, parser_exec_t,
|
|
|
|
const char *, const struct kwinst *, size_t, struct parser *);
|
|
|
|
struct pranges *pranges_create(const char *, parser_exec_t, const char *,
|
|
|
|
const struct intrange *, size_t, struct parser *);
|
|
|
|
struct pbranch *pbranch_create(const char *, const struct branch *, size_t,
|
|
|
|
bool);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int pbranch_addbranch(struct pbranch *, struct parser *);
|
2008-05-06 08:33:42 +04:00
|
|
|
int pbranch_setbranches(struct pbranch *, const struct branch *, size_t);
|
|
|
|
|
|
|
|
int parse(int, char **, const struct parser *, struct match *, size_t *, int *);
|
|
|
|
|
|
|
|
int matches_exec(const struct match *, prop_dictionary_t, size_t);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int parser_init(struct parser *);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
#endif /* _IFCONFIG_PARSE_H */
|