mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-22 23:55:34 +08:00
pfctl: Adapt for RTEMS.
This commit is contained in:
parent
686583cba4
commit
d79524e4a7
42
freebsd/contrib/pf/pfctl/parse-data.h
Normal file
42
freebsd/contrib/pf/pfctl/parse-data.h
Normal file
@ -0,0 +1,42 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct antispoof_opts antispoof_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int blockpolicy);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int debug);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int default_statelock);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct file *file);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct files files);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct filter_opts filter_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct node_hfsc_opts hfsc_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct node_state_opt *keep_state_defaults);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct loadanchorshead loadanchorshead);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char *parsebuf);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int parseindex);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct pfctl *pf);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct pool_opts pool_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char pushback_buffer[]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int pushback_index);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct queue_opts queue_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct node_queue *queues);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int require_order);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static u_int16_t returnicmp6default);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static u_int16_t returnicmpdefault);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int rulestate);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct scrub_opts scrub_opts);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct symhead symhead);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct table_opts table_opts);
|
||||
|
||||
/* NOTE: the following variables are generated by yacc and may change with yacc
|
||||
* version or generation options. */
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static YYSTACKDATA yystack);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int yychar);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int yydebug);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int yyerrflag);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern YYSTYPE yylval);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int yynerrs);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern YYSTYPE yyval);
|
@ -29,6 +29,7 @@
|
||||
%{
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#define pf_find_or_create_ruleset _bsd_pf_find_or_create_ruleset
|
||||
#define pf_anchor_setup _bsd_pf_anchor_setup
|
||||
#define pf_remove_if_empty_ruleset _bsd_pf_remove_if_empty_ruleset
|
||||
@ -6133,3 +6134,6 @@ rt_tableid_max(void)
|
||||
return (RT_TABLEID_MAX);
|
||||
#endif
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "parse-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
@ -32,6 +32,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
|
26
freebsd/contrib/pf/pfctl/pfctl-data.h
Normal file
26
freebsd/contrib/pf/pfctl/pfctl-data.h
Normal file
@ -0,0 +1,26 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int altqsupport);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*anchoropt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *clearopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *debugopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int dev);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int first_title);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*ifaceopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int labels);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, extern int loadopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *optiopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct pf_anchor_global pf_anchors);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *pf_device);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct pf_anchor pf_main_anchor);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*rulesopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *showopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*src_node_kill[2]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int src_node_killers);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*state_kill[2]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int state_killers);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char*tableopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *tblcmdopt);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static const char *tblcmdopt);
|
@ -33,6 +33,19 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
|
||||
#define __need_getopt_newlib
|
||||
#include <getopt.h>
|
||||
|
||||
/* We need some functions from kernel space. */
|
||||
#define pf_get_ruleset_number _bsd_pf_get_ruleset_number
|
||||
#define pf_init_ruleset _bsd_pf_init_ruleset
|
||||
|
||||
#include <rtems/linkersets.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -292,7 +305,11 @@ static const int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT };
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
extern char *__progname;
|
||||
#else /* __rtems__ */
|
||||
#define __progname "pfctl"
|
||||
#endif /* __rtems__ */
|
||||
|
||||
fprintf(stderr, "usage: %s [-AdeghmNnOPqRrvz] ", __progname);
|
||||
fprintf(stderr, "[-a anchor] [-D macro=value] [-F modifier]\n");
|
||||
@ -1645,6 +1662,7 @@ pfctl_init_options(struct pfctl *pf)
|
||||
pf->limit[PF_LIMIT_TABLES] = PFR_KTABLE_HIWAT;
|
||||
pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT;
|
||||
|
||||
#ifndef __rtems__
|
||||
mib[0] = CTL_HW;
|
||||
#ifdef __FreeBSD__
|
||||
mib[1] = HW_PHYSMEM;
|
||||
@ -1655,6 +1673,7 @@ pfctl_init_options(struct pfctl *pf)
|
||||
if (sysctl(mib, 2, &mem, &size, NULL, 0) == -1)
|
||||
err(1, "sysctl");
|
||||
if (mem <= 100*1024*1024)
|
||||
#endif /* __rtems__ */
|
||||
pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT_SMALL;
|
||||
|
||||
pf->debug = PF_DEBUG_URGENT;
|
||||
@ -2069,6 +2088,27 @@ pfctl_lookup_option(char *cmd, const char * const *list)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
static int main(int argc, char *argv[]);
|
||||
|
||||
RTEMS_LINKER_RWSET(bsd_prog_pfctl, char);
|
||||
|
||||
int
|
||||
rtems_bsd_command_pfctl(int argc, char *argv[])
|
||||
{
|
||||
int exit_code = EXIT_FAILURE;
|
||||
const void *data_buf = RTEMS_LINKER_SET_BEGIN(bsd_prog_pfctl);
|
||||
const size_t data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_pfctl);
|
||||
|
||||
rtems_bsd_program_lock();
|
||||
exit_code = rtems_bsd_program_call_main_with_data_restore("pfctl",
|
||||
main, argc, argv, data_buf, data_size);
|
||||
rtems_bsd_program_unlock();
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@ -2080,6 +2120,16 @@ main(int argc, char *argv[])
|
||||
char anchorname[MAXPATHLEN];
|
||||
char *path;
|
||||
|
||||
#ifdef __rtems__
|
||||
struct getopt_data getopt_data;
|
||||
memset(&getopt_data, 0, sizeof(getopt_data));
|
||||
#define optind getopt_data.optind
|
||||
#define optarg getopt_data.optarg
|
||||
#define opterr getopt_data.opterr
|
||||
#define optopt getopt_data.optopt
|
||||
#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data)
|
||||
#endif /* __rtems__ */
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
@ -2471,3 +2521,6 @@ main(int argc, char *argv[])
|
||||
|
||||
exit(error);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
8
freebsd/contrib/pf/pfctl/pfctl_altq-data.h
Normal file
8
freebsd/contrib/pf/pfctl/pfctl_altq-data.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct altqs altqs);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct gen_sc rtsc);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct gen_sc lssc);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static char r2sbuf[R2S_BUFS][RATESTR_MAX]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int r2sidx);
|
@ -20,6 +20,9 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -1276,3 +1279,6 @@ print_hfsc_sc(const char *scname, u_int m1, u_int d, u_int m2,
|
||||
if (d != 0)
|
||||
printf(")");
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_altq-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
13
freebsd/contrib/pf/pfctl/pfctl_optimize-data.h
Normal file
13
freebsd/contrib/pf/pfctl/pfctl_optimize-data.h
Normal file
@ -0,0 +1,13 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int add_opt_table_num);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int pf_opt_create_table_num);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct pf_rule_field pf_rule_desc[]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int
|
||||
(*skip_comparitors[PF_SKIP_COUNT])(struct pf_rule *, struct pf_rule *));
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static const char *skip_comparitors_names[PF_SKIP_COUNT]);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl,
|
||||
static struct pfr_buffer table_buffer);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int table_identifier);
|
@ -18,6 +18,12 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
|
||||
/* We need some functions from kernel space. */
|
||||
#define pf_find_or_create_ruleset _bsd_pf_find_or_create_ruleset
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -1692,4 +1698,6 @@ superblock_free(struct pfctl *pf, struct superblock *block)
|
||||
superblock_free(pf, block->sb_profiled_block);
|
||||
free(block);
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_optimize-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
7
freebsd/contrib/pf/pfctl/pfctl_osfp-data.h
Normal file
7
freebsd/contrib/pf/pfctl/pfctl_osfp-data.h
Normal file
@ -0,0 +1,7 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int class_count);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct name_list classes);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static int fingerprint_count);
|
||||
/* There is also one static buffer called "buf". But this can be ignored. See
|
||||
* comment in source file. */
|
@ -18,6 +18,9 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
@ -1125,3 +1128,6 @@ print_ioctl(struct pf_osfp_ioctl *fp)
|
||||
|
||||
return (buf);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_osfp-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
3
freebsd/contrib/pf/pfctl/pfctl_parser-data.h
Normal file
3
freebsd/contrib/pf/pfctl/pfctl_parser-data.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct node_host *iftab);
|
@ -33,6 +33,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -40,6 +43,9 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#ifdef __rtems__
|
||||
#include <rtems/bsd/sys/errno.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/proc.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
@ -1767,3 +1773,6 @@ pfctl_trans(int dev, struct pfr_buffer *buf, u_long cmd, int from)
|
||||
trans.array = ((struct pfioc_trans_e *)buf->pfrb_caddr) + from;
|
||||
return ioctl(dev, cmd, &trans);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_parser-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
3
freebsd/contrib/pf/pfctl/pfctl_qstats-data.h
Normal file
3
freebsd/contrib/pf/pfctl/pfctl_qstats-data.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static u_int32_t last_ticket);
|
@ -18,6 +18,9 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -455,3 +458,6 @@ update_avg(struct pf_altq_node *a)
|
||||
if (n < AVGN_MAX)
|
||||
qs->avgn++;
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_qstats-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
3
freebsd/contrib/pf/pfctl/pfctl_radix-data.h
Normal file
3
freebsd/contrib/pf/pfctl/pfctl_radix-data.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <rtems/linkersets.h>
|
||||
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char next_ch);
|
@ -32,6 +32,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -48,6 +51,9 @@ __FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#ifdef __rtems__
|
||||
#define SIZE_T_MAX SIZE_MAX
|
||||
#endif /* __rtems__ */
|
||||
#include <err.h>
|
||||
|
||||
#include "pfctl.h"
|
||||
@ -594,3 +600,6 @@ pfr_strerror(int errnum)
|
||||
return strerror(errnum);
|
||||
}
|
||||
}
|
||||
#ifdef __rtems__
|
||||
#include "pfctl_radix-data.h"
|
||||
#endif /* __rtems__ */
|
||||
|
@ -32,6 +32,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -495,7 +498,11 @@ print_astats(struct pfr_astats *as, int dns)
|
||||
void
|
||||
radix_perror(void)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
extern char *__progname;
|
||||
#else /* __rtems__ */
|
||||
#define __progname "pfctl"
|
||||
#endif /* __rtems__ */
|
||||
fprintf(stderr, "%s: %s.\n", __progname, pfr_strerror(errno));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user