|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ogs-ipfw.h" |
|
|
|
|
|
struct cmdline_opts { |
|
|
|
|
|
int do_value_as_ip; |
|
|
int do_resolv; |
|
|
int do_time; |
|
|
int do_quiet; |
|
|
int do_pipe; |
|
|
int do_nat; |
|
|
int do_dynamic; |
|
|
int do_expired; |
|
|
int do_compact; |
|
|
int do_force; |
|
|
int show_sets; |
|
|
int test_only; |
|
|
int comment_only; |
|
|
int verbose; |
|
|
|
|
|
|
|
|
|
|
|
int do_sort; |
|
|
|
|
|
|
|
|
int use_set; |
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
extern struct cmdline_opts co; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct _s_x { |
|
|
char const *s; |
|
|
int x; |
|
|
}; |
|
|
|
|
|
extern struct _s_x f_ipdscp[]; |
|
|
|
|
|
enum tokens { |
|
|
TOK_NULL=0, |
|
|
|
|
|
TOK_OR, |
|
|
TOK_NOT, |
|
|
TOK_STARTBRACE, |
|
|
TOK_ENDBRACE, |
|
|
|
|
|
TOK_ACCEPT, |
|
|
TOK_COUNT, |
|
|
TOK_PIPE, |
|
|
TOK_LINK, |
|
|
TOK_QUEUE, |
|
|
TOK_FLOWSET, |
|
|
TOK_SCHED, |
|
|
TOK_DIVERT, |
|
|
TOK_TEE, |
|
|
TOK_NETGRAPH, |
|
|
TOK_NGTEE, |
|
|
TOK_FORWARD, |
|
|
TOK_SKIPTO, |
|
|
TOK_DENY, |
|
|
TOK_REJECT, |
|
|
TOK_RESET, |
|
|
TOK_UNREACH, |
|
|
TOK_CHECKSTATE, |
|
|
TOK_NAT, |
|
|
TOK_REASS, |
|
|
TOK_CALL, |
|
|
TOK_RETURN, |
|
|
|
|
|
TOK_ALTQ, |
|
|
TOK_LOG, |
|
|
TOK_TAG, |
|
|
TOK_UNTAG, |
|
|
|
|
|
TOK_TAGGED, |
|
|
TOK_UID, |
|
|
TOK_GID, |
|
|
TOK_JAIL, |
|
|
TOK_IN, |
|
|
TOK_LIMIT, |
|
|
TOK_KEEPSTATE, |
|
|
TOK_LAYER2, |
|
|
TOK_OUT, |
|
|
TOK_DIVERTED, |
|
|
TOK_DIVERTEDLOOPBACK, |
|
|
TOK_DIVERTEDOUTPUT, |
|
|
TOK_XMIT, |
|
|
TOK_RECV, |
|
|
TOK_VIA, |
|
|
TOK_FRAG, |
|
|
TOK_IPOPTS, |
|
|
TOK_IPLEN, |
|
|
TOK_IPID, |
|
|
TOK_IPPRECEDENCE, |
|
|
TOK_DSCP, |
|
|
TOK_IPTOS, |
|
|
TOK_IPTTL, |
|
|
TOK_IPVER, |
|
|
TOK_ESTAB, |
|
|
TOK_SETUP, |
|
|
TOK_TCPDATALEN, |
|
|
TOK_TCPFLAGS, |
|
|
TOK_TCPOPTS, |
|
|
TOK_TCPSEQ, |
|
|
TOK_TCPACK, |
|
|
TOK_TCPWIN, |
|
|
TOK_ICMPTYPES, |
|
|
TOK_MAC, |
|
|
TOK_MACTYPE, |
|
|
TOK_VERREVPATH, |
|
|
TOK_VERSRCREACH, |
|
|
TOK_ANTISPOOF, |
|
|
TOK_IPSEC, |
|
|
TOK_COMMENT, |
|
|
|
|
|
TOK_PLR, |
|
|
TOK_NOERROR, |
|
|
TOK_BUCKETS, |
|
|
TOK_DSTIP, |
|
|
TOK_SRCIP, |
|
|
TOK_DSTPORT, |
|
|
TOK_SRCPORT, |
|
|
TOK_ALL, |
|
|
TOK_MASK, |
|
|
TOK_FLOW_MASK, |
|
|
TOK_SCHED_MASK, |
|
|
TOK_BW, |
|
|
TOK_DELAY, |
|
|
TOK_PROFILE, |
|
|
TOK_BURST, |
|
|
TOK_RED, |
|
|
TOK_GRED, |
|
|
TOK_ECN, |
|
|
TOK_DROPTAIL, |
|
|
TOK_PROTO, |
|
|
|
|
|
TOK_WEIGHT, |
|
|
TOK_LMAX, |
|
|
TOK_PRI, |
|
|
TOK_TYPE, |
|
|
TOK_SLOTSIZE, |
|
|
|
|
|
TOK_IP, |
|
|
TOK_IF, |
|
|
TOK_ALOG, |
|
|
TOK_DENY_INC, |
|
|
TOK_SAME_PORTS, |
|
|
TOK_UNREG_ONLY, |
|
|
TOK_SKIP_GLOBAL, |
|
|
TOK_RESET_ADDR, |
|
|
TOK_ALIAS_REV, |
|
|
TOK_PROXY_ONLY, |
|
|
TOK_REDIR_ADDR, |
|
|
TOK_REDIR_PORT, |
|
|
TOK_REDIR_PROTO, |
|
|
|
|
|
TOK_IPV6, |
|
|
TOK_FLOWID, |
|
|
TOK_ICMP6TYPES, |
|
|
TOK_EXT6HDR, |
|
|
TOK_DSTIP6, |
|
|
TOK_SRCIP6, |
|
|
|
|
|
TOK_IPV4, |
|
|
TOK_UNREACH6, |
|
|
TOK_RESET6, |
|
|
|
|
|
TOK_FIB, |
|
|
TOK_SETFIB, |
|
|
TOK_LOOKUP, |
|
|
TOK_SOCKARG, |
|
|
TOK_SETDSCP, |
|
|
TOK_FLOW, |
|
|
TOK_IFLIST, |
|
|
|
|
|
TOK_CREATE, |
|
|
TOK_DESTROY, |
|
|
TOK_LIST, |
|
|
TOK_INFO, |
|
|
TOK_DETAIL, |
|
|
TOK_MODIFY, |
|
|
TOK_FLUSH, |
|
|
TOK_SWAP, |
|
|
TOK_ADD, |
|
|
TOK_DEL, |
|
|
TOK_VALTYPE, |
|
|
TOK_ALGO, |
|
|
TOK_TALIST, |
|
|
TOK_ATOMIC, |
|
|
TOK_LOCK, |
|
|
TOK_UNLOCK, |
|
|
TOK_VLIST, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NEED(_p, msg) {if (!_p) errx(EX_USAGE, msg);} |
|
|
#define NEED1(msg) {if (!(*av)) errx(EX_USAGE, msg);} |
|
|
|
|
|
struct buf_pr { |
|
|
char *buf; |
|
|
char *ptr; |
|
|
size_t size; |
|
|
size_t avail; |
|
|
size_t needed; |
|
|
}; |
|
|
|
|
|
int pr_u64(struct buf_pr *bp, uint64_t *pd, int width); |
|
|
int bp_alloc(struct buf_pr *b, size_t size); |
|
|
void bp_free(struct buf_pr *b); |
|
|
int bprintf(struct buf_pr *b, char *format, ...); |
|
|
|
|
|
|
|
|
|
|
|
void *safe_calloc(size_t number, size_t size); |
|
|
void *safe_realloc(void *ptr, size_t size); |
|
|
|
|
|
|
|
|
int _substrcmp(const char *str1, const char* str2); |
|
|
int _substrcmp2(const char *str1, const char* str2, const char* str3); |
|
|
int stringnum_cmp(const char *a, const char *b); |
|
|
|
|
|
|
|
|
int match_token(struct _s_x *table, char *string); |
|
|
int match_token_relaxed(struct _s_x *table, char *string); |
|
|
char const *match_value(struct _s_x *p, int value); |
|
|
size_t concat_tokens(char *buf, size_t bufsize, struct _s_x *table, |
|
|
char *delimiter); |
|
|
int fill_flags(struct _s_x *flags, char *p, char **e, uint32_t *set, |
|
|
uint32_t *clear); |
|
|
void print_flags_buffer(char *buf, size_t sz, struct _s_x *list, uint32_t set); |
|
|
|
|
|
struct _ip_fw3_opheader; |
|
|
int do_cmd(int optname, void *optval, uintptr_t optlen); |
|
|
int do_set3(int optname, struct _ip_fw3_opheader *op3, uintptr_t optlen); |
|
|
int do_get3(int optname, struct _ip_fw3_opheader *op3, size_t *optlen); |
|
|
|
|
|
struct in6_addr; |
|
|
void n2mask(struct in6_addr *mask, int n); |
|
|
int contigmask(uint8_t *p, int len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct _ipfw_insn; |
|
|
struct _ipfw_insn_altq; |
|
|
struct _ipfw_insn_u32; |
|
|
struct _ipfw_insn_ip6; |
|
|
struct _ipfw_insn_icmp6; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern int resvd_set_number; |
|
|
|
|
|
|
|
|
void ipfw_add(char *av[]); |
|
|
void ipfw_show_nat(int ac, char **av); |
|
|
void ipfw_config_pipe(int ac, char **av); |
|
|
void ipfw_config_nat(int ac, char **av); |
|
|
void ipfw_sets_handler(char *av[]); |
|
|
void ipfw_table_handler(int ac, char *av[]); |
|
|
void ipfw_sysctl_handler(char *av[], int which); |
|
|
void ipfw_delete(char *av[]); |
|
|
void ipfw_flush(int force); |
|
|
void ipfw_zero(int ac, char *av[], int optname); |
|
|
void ipfw_list(int ac, char *av[], int show_counters); |
|
|
void ipfw_internal_handler(int ac, char *av[]); |
|
|
|
|
|
#ifdef PF |
|
|
|
|
|
void altq_set_enabled(int enabled); |
|
|
u_int32_t altq_name_to_qid(const char *name); |
|
|
void print_altq_cmd(struct buf_pr *bp, struct _ipfw_insn_altq *altqptr); |
|
|
#else |
|
|
#define NO_ALTQ |
|
|
#endif |
|
|
|
|
|
|
|
|
void dummynet_list(int ac, char *av[], int show_counters); |
|
|
void dummynet_flush(void); |
|
|
int ipfw_delete_pipe(int pipe_or_queue, int n); |
|
|
|
|
|
|
|
|
void print_unreach6_code(uint16_t code); |
|
|
void print_ip6(struct buf_pr *bp, struct _ipfw_insn_ip6 *cmd, char const *s); |
|
|
void print_flow6id(struct buf_pr *bp, struct _ipfw_insn_u32 *cmd); |
|
|
void print_icmp6types(struct buf_pr *bp, struct _ipfw_insn_u32 *cmd); |
|
|
void print_ext6hdr(struct buf_pr *bp, struct _ipfw_insn *cmd ); |
|
|
|
|
|
struct _ipfw_insn *add_srcip6(struct _ipfw_insn *cmd, char *av, int cblen); |
|
|
struct _ipfw_insn *add_dstip6(struct _ipfw_insn *cmd, char *av, int cblen); |
|
|
|
|
|
void fill_flow6(struct _ipfw_insn_u32 *cmd, char *av, int cblen); |
|
|
void fill_unreach6_code(u_short *codep, char *str); |
|
|
void fill_icmp6types(struct _ipfw_insn_icmp6 *cmd, char *av, int cblen); |
|
|
int fill_ext6hdr(struct _ipfw_insn *cmd, char *av); |
|
|
|
|
|
|
|
|
struct _ipfw_obj_ctlv; |
|
|
char *table_search_ctlv(struct _ipfw_obj_ctlv *ctlv, uint16_t idx); |
|
|
void table_sort_ctlv(struct _ipfw_obj_ctlv *ctlv); |
|
|
int table_check_name(char *tablename); |
|
|
void ipfw_list_ta(int ac, char *av[]); |
|
|
void ipfw_list_values(int ac, char *av[]); |
|
|
|
|
|
|