Index: freebsd/contrib/pf/pfctl/parse-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/parse-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/parse-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -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);
Index: freebsd/contrib/pf/pfctl/parse.y
===================================================================
--- freebsd/contrib/pf/pfctl/parse.y	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/parse.y	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -30,4 +30,5 @@
 #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
@@ -6134,2 +6135,5 @@
 #endif
 }
+#ifdef __rtems__
+#include "parse-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pf_print_state.c
===================================================================
--- freebsd/contrib/pf/pfctl/pf_print_state.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pf_print_state.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -33,4 +33,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
Index: freebsd/contrib/pf/pfctl/pfctl-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -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);
Index: freebsd/contrib/pf/pfctl/pfctl.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -34,4 +34,17 @@
  */
 
+#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$");
@@ -293,5 +306,9 @@
 usage(void)
 {
+#ifndef __rtems__
 	extern char *__progname;
+#else /* __rtems__ */
+#define __progname "pfctl"
+#endif /* __rtems__ */
 
 	fprintf(stderr, "usage: %s [-AdeghmNnOPqRrvz] ", __progname);
@@ -1646,4 +1663,5 @@
 	pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT;
 
+#ifndef __rtems__
 	mib[0] = CTL_HW;
 #ifdef __FreeBSD__
@@ -1656,4 +1674,5 @@
 		err(1, "sysctl");
 	if (mem <= 100*1024*1024)
+#endif /* __rtems__ */
 		pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT_SMALL; 
 
@@ -2070,4 +2089,25 @@
 }
 
+#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,4 +2120,14 @@
 	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)
@@ -2472,2 +2522,5 @@
 	exit(error);
 }
+#ifdef __rtems__
+#include "pfctl-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_altq-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_altq-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_altq-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -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);
Index: freebsd/contrib/pf/pfctl/pfctl_altq.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_altq.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_altq.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -21,4 +21,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -1277,2 +1280,5 @@
 		printf(")");
 }
+#ifdef __rtems__
+#include "pfctl_altq-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_optimize-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_optimize-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_optimize-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -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);
Index: freebsd/contrib/pf/pfctl/pfctl_optimize.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_optimize.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_optimize.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -19,4 +19,10 @@
  */
 
+#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$");
@@ -1693,3 +1699,5 @@
 	free(block);
 }
-
+#ifdef __rtems__
+#include "pfctl_optimize-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_osfp-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_osfp-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_osfp-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -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. */
Index: freebsd/contrib/pf/pfctl/pfctl_osfp.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_osfp.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_osfp.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -19,4 +19,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <rtems/bsd/sys/types.h>
 #include <sys/ioctl.h>
@@ -1126,2 +1129,5 @@
 	return (buf);
 }
+#ifdef __rtems__
+#include "pfctl_osfp-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_parser-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_parser-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_parser-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -0,0 +1,3 @@
+#include <rtems/linkersets.h>
+
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static struct node_host *iftab);
Index: freebsd/contrib/pf/pfctl/pfctl_parser.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_parser.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_parser.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -34,4 +34,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -41,4 +44,7 @@
 #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>
@@ -1768,2 +1774,5 @@
 	return ioctl(dev, cmd, &trans);
 }
+#ifdef __rtems__
+#include "pfctl_parser-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_qstats-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_qstats-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_qstats-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -0,0 +1,3 @@
+#include <rtems/linkersets.h>
+
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static u_int32_t last_ticket);
Index: freebsd/contrib/pf/pfctl/pfctl_qstats.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_qstats.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_qstats.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -19,4 +19,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -456,2 +459,5 @@
 		qs->avgn++;
 }
+#ifdef __rtems__
+#include "pfctl_qstats-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_radix-data.h
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_radix-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
+++ freebsd/contrib/pf/pfctl/pfctl_radix-data.h	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -0,0 +1,3 @@
+#include <rtems/linkersets.h>
+
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_pfctl, static char next_ch);
Index: freebsd/contrib/pf/pfctl/pfctl_radix.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_radix.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_radix.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -33,4 +33,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -49,4 +52,7 @@
 #include <stdlib.h>
 #include <limits.h>
+#ifdef __rtems__
+#define SIZE_T_MAX SIZE_MAX
+#endif /* __rtems__ */
 #include <err.h>
 
@@ -595,2 +601,5 @@
 	}
 }
+#ifdef __rtems__
+#include "pfctl_radix-data.h"
+#endif /* __rtems__ */
Index: freebsd/contrib/pf/pfctl/pfctl_table.c
===================================================================
--- freebsd/contrib/pf/pfctl/pfctl_table.c	(revision 85dd33213b46c7c77f0fe9788d0675398501ecc2)
+++ freebsd/contrib/pf/pfctl/pfctl_table.c	(revision 4831944a2b4204c907018ad99fdaef2e48c604ad)
@@ -33,4 +33,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -496,5 +499,9 @@
 radix_perror(void)
 {
+#ifndef __rtems__
 	extern char *__progname;
+#else /* __rtems__ */
+#define __progname "pfctl"
+#endif /* __rtems__ */
 	fprintf(stderr, "%s: %s.\n", __progname, pfr_strerror(errno));
 }
