1/*
2 * Copyright (C) 2002-2012 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6#if defined(KERNEL) || defined(_KERNEL)
7# undef KERNEL
8# undef _KERNEL
9# define        KERNEL	1
10# define        _KERNEL	1
11#endif
12#include <sys/param.h>
13#include <sys/errno.h>
14#include <sys/types.h>
15#include <sys/time.h>
16#include <sys/file.h>
17#if defined(__FreeBSD__) && defined(_KERNEL)
18# include <sys/fcntl.h>
19# include <sys/filio.h>
20#else
21# include <sys/ioctl.h>
22#endif
23#if !defined(_KERNEL)
24# include <string.h>
25# define _KERNEL
26# include <sys/uio.h>
27# undef _KERNEL
28#endif
29#include <sys/socket.h>
30#include <net/if.h>
31#if defined(__FreeBSD__)
32#  include <sys/cdefs.h>
33#  include <sys/proc.h>
34#endif
35#if defined(_KERNEL)
36# include <sys/systm.h>
37# if !defined(__SVR4)
38#  include <sys/mbuf.h>
39# endif
40#endif
41#include <netinet/in.h>
42
43#include "netinet/ip_compat.h"
44#include "netinet/ip_fil.h"
45#include "netinet/ip_pool.h"
46#include "netinet/ip_htable.h"
47#include "netinet/ip_lookup.h"
48#include "netinet/ip_nat.h"
49#include "netinet/ip_state.h"
50#include "netinet/ip_proxy.h"
51#include "netinet/ip_auth.h"
52/* END OF INCLUDES */
53
54/*
55 * NetBSD has moved to 64bit time_t for all architectures.
56 * For some, such as sparc64, there is no change because long is already
57 * 64bit, but for others (i386), there is...
58 */
59#ifdef IPFILTER_COMPAT
60
61# ifdef __NetBSD__
62typedef struct timeval_l {
63	long	tv_sec;
64	long	tv_usec;
65} timeval_l_t;
66# endif
67
68/* ------------------------------------------------------------------------ */
69
70typedef struct tcpinfo4 {
71	u_short		ts_sport;
72	u_short		ts_dport;
73	tcpdata_t	ts_data[2];
74} tcpinfo4_t;
75
76static void ipf_v5tcpinfoto4(tcpinfo_t *, tcpinfo4_t *);
77
78static void
79ipf_v5tcpinfoto4(v5, v4)
80	tcpinfo_t *v5;
81	tcpinfo4_t *v4;
82{
83	v4->ts_sport = v5->ts_sport;
84	v4->ts_dport = v5->ts_dport;
85	v4->ts_data[0] = v5->ts_data[0];
86	v4->ts_data[1] = v5->ts_data[1];
87}
88
89typedef struct	fr_ip4	{
90	u_32_t	fi_v:4;
91	u_32_t	fi_xx:4;
92	u_32_t	fi_tos:8;
93	u_32_t	fi_ttl:8;
94	u_32_t	fi_p:8;
95	u_32_t	fi_optmsk;
96	i6addr_t fi_src;
97	i6addr_t fi_dst;
98	u_short	ofi_secmsk;
99	u_short	ofi_auth;
100	u_32_t	fi_flx;
101	u_32_t	fi_tcpmsk;
102	u_32_t	fi_res1;
103} frip4_t;
104
105typedef struct	frpcmp4	{
106	int	frp_cmp;
107	u_short	frp_port;
108	u_short	frp_top;
109} frpcmp4_t;
110
111typedef	struct	frtuc4	{
112	u_char	ftu_tcpfm;
113	u_char	ftu_tcpf;
114	frpcmp4_t	ftu_src;
115	frpcmp4_t	ftu_dst;
116} frtuc4_t;
117
118typedef	struct	fripf4	{
119	frip4_t fri_ip;
120	frip4_t fri_mip;
121
122	u_short	fri_icmpm;
123	u_short	fri_icmp;
124
125	frtuc4_t	fri_tuc;
126	int	fri_satype;
127	int	fri_datype;
128	int	fri_sifpidx;
129	int	fri_difpidx;
130} fripf4_t;
131
132typedef struct frdest_4 {
133	void		*fd_ifp;
134	i6addr_t	ofd_ip6;
135	char		fd_ifname[LIFNAMSIZ];
136} frdest_4_t;
137
138/* ------------------------------------------------------------------------ */
139
140/* 5.1.0 new release (current)
141 * 4.1.34 changed the size of the time structure used for pps
142 * 4.1.16 moved the location of fr_flineno
143 * 4.1.0 base version
144 */
145typedef	struct	frentry_4_1_34 {
146	ipfmutex_t	fr_lock;
147	struct	frentry	*fr_next;
148	struct	frentry	**fr_grp;
149	struct	ipscan	*fr_isc;
150	void	*fr_ifas[4];
151	void	*fr_ptr;	/* for use with fr_arg */
152	char	*fr_comment;	/* text comment for rule */
153	int	fr_ref;		/* reference count - for grouping */
154	int	fr_statecnt;	/* state count - for limit rules */
155	int	fr_flineno;	/* line number from conf file */
156	U_QUAD_T	fr_hits;
157	U_QUAD_T	fr_bytes;
158	union {
159		struct timeval	frp_lastpkt;
160		char	frp_bytes[12];
161	} fr_lpu;
162	int		fr_curpps;
163	union	{
164		void		*fru_data;
165		char		*fru_caddr;
166		fripf4_t	*fru_ipf;
167		frentfunc_t	fru_func;
168	} fr_dun;
169	ipfunc_t fr_func; 	/* call this function */
170	int	fr_dsize;
171	int	fr_pps;
172	int	fr_statemax;	/* max reference count */
173	u_32_t	fr_type;
174	u_32_t	fr_flags;	/* per-rule flags && options (see below) */
175	u_32_t	fr_logtag;	/* user defined log tag # */
176	u_32_t	fr_collect;	/* collection number */
177	u_int	fr_arg;		/* misc. numeric arg for rule */
178	u_int	fr_loglevel;	/* syslog log facility + priority */
179	u_int	fr_age[2];	/* non-TCP timeouts */
180	u_char	fr_v;
181	u_char	fr_icode;	/* return ICMP code */
182	char	fr_group[FR_GROUPLEN];	/* group to which this rule belongs */
183	char	fr_grhead[FR_GROUPLEN];	/* group # which this rule starts */
184	ipftag_t fr_nattag;
185	char	fr_ifnames[4][LIFNAMSIZ];
186	char	fr_isctag[16];
187	frdest_4_t fr_tifs[2];	/* "to"/"reply-to" interface */
188	frdest_4_t fr_dif;	/* duplicate packet interface */
189	u_int	fr_cksum;	/* checksum on filter rules for performance */
190} frentry_4_1_34_t;
191
192typedef	struct	frentry_4_1_16 {
193	ipfmutex_t	fr_lock;
194	struct	frentry	*fr_next;
195	struct	frentry	**fr_grp;
196	struct	ipscan	*fr_isc;
197	void	*fr_ifas[4];
198	void	*fr_ptr;
199	char	*fr_comment;
200	int	fr_ref;
201	int	fr_statecnt;
202	int	fr_flineno;
203	U_QUAD_T	fr_hits;
204	U_QUAD_T	fr_bytes;
205	union {
206#ifdef __NetBSD__
207		timeval_l_t	frp_lastpkt;
208#else
209		struct timeval	frp_lastpkt;
210#endif
211	} fr_lpu;
212	int		fr_curpps;
213	union	{
214		void		*fru_data;
215		caddr_t		fru_caddr;
216		fripf4_t	*fru_ipf;
217		frentfunc_t	fru_func;
218	} fr_dun;
219	ipfunc_t fr_func;
220	int	fr_dsize;
221	int	fr_pps;
222	int	fr_statemax;
223	u_32_t	fr_type;
224	u_32_t	fr_flags;
225	u_32_t	fr_logtag;
226	u_32_t	fr_collect;
227	u_int	fr_arg;
228	u_int	fr_loglevel;
229	u_int	fr_age[2];
230	u_char	fr_v;
231	u_char	fr_icode;
232	char	fr_group[FR_GROUPLEN];
233	char	fr_grhead[FR_GROUPLEN];
234	ipftag_t fr_nattag;
235	char	fr_ifnames[4][LIFNAMSIZ];
236	char	fr_isctag[16];
237	frdest_4_t fr_tifs[2];
238	frdest_4_t fr_dif;
239	u_int	fr_cksum;
240} frentry_4_1_16_t;
241
242typedef	struct	frentry_4_1_0 {
243	ipfmutex_t	fr_lock;
244	struct	frentry	*fr_next;
245	struct	frentry	**fr_grp;
246	struct	ipscan	*fr_isc;
247	void	*fr_ifas[4];
248	void	*fr_ptr;
249	char	*fr_comment;
250	int	fr_ref;
251	int	fr_statecnt;
252	U_QUAD_T	fr_hits;
253	U_QUAD_T	fr_bytes;
254	union {
255#ifdef __NetBSD__
256		timeval_l_t	frp_lastpkt;
257#else
258		struct timeval	frp_lastpkt;
259#endif
260	} fr_lpu;
261	int		fr_curpps;
262
263	union	{
264		void		*fru_data;
265		caddr_t		fru_caddr;
266		fripf4_t	*fru_ipf;
267		frentfunc_t	fru_func;
268	} fr_dun;
269	/*
270	 * Fields after this may not change whilst in the kernel.
271	 */
272	ipfunc_t fr_func;
273	int	fr_dsize;
274	int	fr_pps;
275	int	fr_statemax;
276	int	fr_flineno;
277	u_32_t	fr_type;
278	u_32_t	fr_flags;
279	u_32_t	fr_logtag;
280	u_32_t	fr_collect;
281	u_int	fr_arg;
282	u_int	fr_loglevel;
283	u_int	fr_age[2];
284	u_char	fr_v;
285	u_char	fr_icode;
286	char	fr_group[FR_GROUPLEN];
287	char	fr_grhead[FR_GROUPLEN];
288	ipftag_t fr_nattag;
289	char	fr_ifnames[4][LIFNAMSIZ];
290	char	fr_isctag[16];
291	frdest_4_t fr_tifs[2];
292	frdest_4_t fr_dif;
293	u_int	fr_cksum;
294} frentry_4_1_0_t;
295
296/* ------------------------------------------------------------------------ */
297
298/*
299 * 5.1.0  new release (current)
300 * 4.1.32 removed both fin_state and fin_nat, added fin_pktnum
301 * 4.1.24 added fin_cksum
302 * 4.1.23 added fin_exthdr
303 * 4.1.11 added fin_ifname
304 * 4.1.4  added fin_hbuf
305 */
306typedef	struct	fr_info_4_1_32 {
307	void	*fin_ifp;		/* interface packet is `on' */
308	frip4_t	fin_fi;		/* IP Packet summary */
309	union	{
310		u_short	fid_16[2];	/* TCP/UDP ports, ICMP code/type */
311		u_32_t	fid_32;
312	} fin_dat;
313	int	fin_out;		/* in or out ? 1 == out, 0 == in */
314	int	fin_rev;		/* state only: 1 = reverse */
315	u_short	fin_hlen;		/* length of IP header in bytes */
316	u_char	ofin_tcpf;		/* TCP header flags (SYN, ACK, etc) */
317	u_char	fin_icode;		/* ICMP error to return */
318	u_32_t	fin_rule;		/* rule # last matched */
319	char	fin_group[FR_GROUPLEN];	/* group number, -1 for none */
320	struct	frentry *fin_fr;	/* last matching rule */
321	void	*fin_dp;		/* start of data past IP header */
322	int	fin_dlen;		/* length of data portion of packet */
323	int	fin_plen;
324	int	fin_ipoff;		/* # bytes from buffer start to hdr */
325	u_short	fin_id;			/* IP packet id field */
326	u_short	fin_off;
327	int	fin_depth;		/* Group nesting depth */
328	int	fin_error;		/* Error code to return */
329	int	fin_cksum;		/* -1 bad, 1 good, 0 not done */
330	u_int	fin_pktnum;
331	void	*fin_nattag;
332	void	*fin_exthdr;
333	ip_t	*ofin_ip;
334	mb_t	**fin_mp;		/* pointer to pointer to mbuf */
335	mb_t	*fin_m;			/* pointer to mbuf */
336#if SOLARIS
337	mb_t	*fin_qfm;		/* pointer to mblk where pkt starts */
338	void	*fin_qpi;
339	char	fin_ifname[LIFNAMSIZ];
340#endif
341} fr_info_4_1_32_t;
342
343typedef struct  fr_info_4_1_24 {
344	void    *fin_ifp;
345	frip4_t fin_fi;
346	union   {
347		u_short fid_16[2];
348		u_32_t  fid_32;
349	} fin_dat;
350	int     fin_out;
351	int     fin_rev;
352	u_short fin_hlen;
353	u_char  ofin_tcpf;
354	u_char  fin_icode;
355	u_32_t  fin_rule;
356	char    fin_group[FR_GROUPLEN];
357	struct  frentry *fin_fr;
358	void    *fin_dp;
359	int     fin_dlen;
360	int     fin_plen;
361	int     fin_ipoff;
362	u_short fin_id;
363	u_short fin_off;
364	int     fin_depth;
365	int     fin_error;
366	int     fin_cksum;
367	void	*fin_state;
368	void	*fin_nat;
369	void    *fin_nattag;
370	void    *fin_exthdr;
371	ip_t    *ofin_ip;
372	mb_t    **fin_mp;
373	mb_t    *fin_m;
374#if SOLARIS
375	mb_t    *fin_qfm;
376	void    *fin_qpi;
377	char    fin_ifname[LIFNAMSIZ];
378#endif
379} fr_info_4_1_24_t;
380
381typedef struct  fr_info_4_1_23 {
382	void    *fin_ifp;
383	frip4_t fin_fi;
384	union   {
385		u_short fid_16[2];
386		u_32_t  fid_32;
387	} fin_dat;
388	int     fin_out;
389	int     fin_rev;
390	u_short fin_hlen;
391	u_char  ofin_tcpf;
392	u_char  fin_icode;
393	u_32_t  fin_rule;
394	char    fin_group[FR_GROUPLEN];
395	struct  frentry *fin_fr;
396	void    *fin_dp;
397	int     fin_dlen;
398	int     fin_plen;
399	int     fin_ipoff;
400	u_short fin_id;
401	u_short fin_off;
402	int     fin_depth;
403	int     fin_error;
404	void	*fin_state;
405	void	*fin_nat;
406	void    *fin_nattag;
407	void    *fin_exthdr;
408	ip_t    *ofin_ip;
409	mb_t    **fin_mp;
410	mb_t    *fin_m;
411#if SOLARIS
412	mb_t    *fin_qfm;
413	void    *fin_qpi;
414	char    fin_ifname[LIFNAMSIZ];
415#endif
416} fr_info_4_1_23_t;
417
418typedef struct  fr_info_4_1_11 {
419	void    *fin_ifp;
420	frip4_t fin_fi;
421	union   {
422		u_short fid_16[2];
423		u_32_t  fid_32;
424	} fin_dat;
425	int     fin_out;
426	int     fin_rev;
427	u_short fin_hlen;
428	u_char  ofin_tcpf;
429	u_char  fin_icode;
430	u_32_t  fin_rule;
431	char    fin_group[FR_GROUPLEN];
432	struct  frentry *fin_fr;
433	void    *fin_dp;
434	int     fin_dlen;
435	int     fin_plen;
436	int     fin_ipoff;
437	u_short fin_id;
438	u_short fin_off;
439	int     fin_depth;
440	int     fin_error;
441	void	*fin_state;
442	void	*fin_nat;
443	void    *fin_nattag;
444	ip_t    *ofin_ip;
445	mb_t    **fin_mp;
446	mb_t    *fin_m;
447#if SOLARIS
448	mb_t    *fin_qfm;
449	void    *fin_qpi;
450	char    fin_ifname[LIFNAMSIZ];
451#endif
452} fr_info_4_1_11_t;
453
454/* ------------------------------------------------------------------------ */
455
456typedef	struct	filterstats_4_1 {
457	u_long	fr_pass;	/* packets allowed */
458	u_long	fr_block;	/* packets denied */
459	u_long	fr_nom;		/* packets which don't match any rule */
460	u_long	fr_short;	/* packets which are short */
461	u_long	fr_ppkl;	/* packets allowed and logged */
462	u_long	fr_bpkl;	/* packets denied and logged */
463	u_long	fr_npkl;	/* packets unmatched and logged */
464	u_long	fr_pkl;		/* packets logged */
465	u_long	fr_skip;	/* packets to be logged but buffer full */
466	u_long	fr_ret;		/* packets for which a return is sent */
467	u_long	fr_acct;	/* packets for which counting was performed */
468	u_long	fr_bnfr;	/* bad attempts to allocate fragment state */
469	u_long	fr_nfr;		/* new fragment state kept */
470	u_long	fr_cfr;		/* add new fragment state but complete pkt */
471	u_long	fr_bads;	/* bad attempts to allocate packet state */
472	u_long	fr_ads;		/* new packet state kept */
473	u_long	fr_chit;	/* cached hit */
474	u_long	fr_tcpbad;	/* TCP checksum check failures */
475	u_long	fr_pull[2];	/* good and bad pullup attempts */
476	u_long	fr_badsrc;	/* source received doesn't match route */
477	u_long	fr_badttl;	/* TTL in packet doesn't reach minimum */
478	u_long	fr_bad;		/* bad IP packets to the filter */
479	u_long	fr_ipv6;	/* IPv6 packets in/out */
480	u_long	fr_ppshit;	/* dropped because of pps ceiling */
481	u_long	fr_ipud;	/* IP id update failures */
482} filterstats_4_1_t;
483
484/*
485 * 5.1.0  new release (current)
486 * 4.1.33 changed the size of f_locks from IPL_LOGMAX to IPL_LOGSIZE
487 */
488typedef	struct	friostat_4_1_33	{
489	struct	filterstats_4_1	of_st[2];
490	struct	frentry	*f_ipf[2][2];
491	struct	frentry	*f_acct[2][2];
492	struct	frentry	*f_ipf6[2][2];
493	struct	frentry	*f_acct6[2][2];
494	struct	frentry	*f_auth;
495	struct	frgroup	*f_groups[IPL_LOGSIZE][2];
496	u_long	f_froute[2];
497	u_long	f_ticks;
498	int	f_locks[IPL_LOGSIZE];
499	size_t	f_kmutex_sz;
500	size_t	f_krwlock_sz;
501	int	f_defpass;	/* default pass - from fr_pass */
502	int	f_active;	/* 1 or 0 - active rule set */
503	int	f_running;	/* 1 if running, else 0 */
504	int	f_logging;	/* 1 if enabled, else 0 */
505	int	f_features;
506	char	f_version[32];	/* version string */
507} friostat_4_1_33_t;
508
509typedef struct friostat_4_1_0	{
510	struct filterstats_4_1 of_st[2];
511	struct frentry	*f_ipf[2][2];
512	struct frentry	*f_acct[2][2];
513	struct frentry	*f_ipf6[2][2];
514	struct frentry	*f_acct6[2][2];
515	struct frentry	*f_auth;
516	struct frgroup	*f_groups[IPL_LOGSIZE][2];
517	u_long	f_froute[2];
518	u_long	f_ticks;
519	int	f_locks[IPL_LOGMAX];
520	size_t	f_kmutex_sz;
521	size_t	f_krwlock_sz;
522	int	f_defpass;
523	int	f_active;
524	int	f_running;
525	int	f_logging;
526	int	f_features;
527	char	f_version[32];
528} friostat_4_1_0_t;
529
530/* ------------------------------------------------------------------------ */
531
532/*
533 * 5.1.0  new release (current)
534 * 4.1.14 added in_lock
535 */
536typedef	struct	ipnat_4_1_14	{
537	ipfmutex_t	in_lock;
538	struct	ipnat	*in_next;		/* NAT rule list next */
539	struct	ipnat	*in_rnext;		/* rdr rule hash next */
540	struct	ipnat	**in_prnext;		/* prior rdr next ptr */
541	struct	ipnat	*in_mnext;		/* map rule hash next */
542	struct	ipnat	**in_pmnext;		/* prior map next ptr */
543	struct	ipftq	*in_tqehead[2];
544	void		*in_ifps[2];
545	void		*in_apr;
546	char		*in_comment;
547	i6addr_t	in_next6;
548	u_long		in_space;
549	u_long		in_hits;
550	u_int		in_use;
551	u_int		in_hv;
552	int		in_flineno;		/* conf. file line number */
553	u_short		in_pnext;
554	u_char		in_v;
555	u_char		in_xxx;
556	/* From here to the end is covered by IPN_CMPSIZ */
557	u_32_t		in_flags;
558	u_32_t		in_mssclamp;		/* if != 0 clamp MSS to this */
559	u_int		in_age[2];
560	int		in_redir;		/* see below for values */
561	int		in_p;			/* protocol. */
562	i6addr_t	in_in[2];
563	i6addr_t	in_out[2];
564	i6addr_t	in_src[2];
565	frtuc4_t	in_tuc;
566	u_short		in_port[2];
567	u_short		in_ppip;		/* ports per IP. */
568	u_short		in_ippip;		/* IP #'s per IP# */
569	char		in_ifnames[2][LIFNAMSIZ];
570	char		in_plabel[APR_LABELLEN];	/* proxy label. */
571	ipftag_t	in_tag;
572} ipnat_4_1_14_t;
573
574typedef	struct	ipnat_4_1_0	{
575	struct	ipnat	*in_next;
576	struct	ipnat	*in_rnext;
577	struct	ipnat	**in_prnext;
578	struct	ipnat	*in_mnext;
579	struct	ipnat	**in_pmnext;
580	struct	ipftq	*in_tqehead[2];
581	void		*in_ifps[2];
582	void		*in_apr;
583	char		*in_comment;
584	i6addr_t	in_next6;
585	u_long		in_space;
586	u_long		in_hits;
587	u_int		in_use;
588	u_int		in_hv;
589	int		in_flineno;
590	u_short		in_pnext;
591	u_char		in_v;
592	u_char		in_xxx;
593	u_32_t		in_flags;
594	u_32_t		in_mssclamp;
595	u_int		in_age[2];
596	int		in_redir;
597	int		in_p;
598	i6addr_t	in_in[2];
599	i6addr_t	in_out[2];
600	i6addr_t	in_src[2];
601	frtuc4_t	in_tuc;
602	u_short		in_port[2];
603	u_short		in_ppip;
604	u_short		in_ippip;
605	char		in_ifnames[2][LIFNAMSIZ];
606	char		in_plabel[APR_LABELLEN];
607	ipftag_t	in_tag;
608} ipnat_4_1_0_t;
609
610/* ------------------------------------------------------------------------ */
611
612typedef	struct	natlookup_4_1_1 {
613	struct	in_addr	onl_inip;
614	struct	in_addr	onl_outip;
615	struct	in_addr	onl_realip;
616	int	nl_flags;
617	u_short	nl_inport;
618	u_short	nl_outport;
619	u_short	nl_realport;
620} natlookup_4_1_1_t;
621
622/* ------------------------------------------------------------------------ */
623
624/*
625 * 4.1.25 added nat_seqnext (current)
626 * 4.1.14 added nat_redir
627 * 4.1.3  moved nat_rev
628 * 4.1.2  added nat_rev
629 */
630typedef	struct	nat_4_1_25	{
631	ipfmutex_t	nat_lock;
632	struct	nat_4_1_25	*nat_next;
633	struct	nat_4_1_25	**nat_pnext;
634	struct	nat_4_1_25	*nat_hnext[2];
635	struct	nat_4_1_25	**nat_phnext[2];
636	struct	hostmap	*nat_hm;
637	void		*nat_data;
638	struct	nat_4_1_25	**nat_me;
639	struct	ipstate	*nat_state;
640	struct	ap_session	*nat_aps;
641	frentry_t	*nat_fr;
642	struct	ipnat_4_1_14	*nat_ptr;
643	void		*nat_ifps[2];
644	void		*nat_sync;
645	ipftqent_t	nat_tqe;
646	u_32_t		nat_flags;
647	u_32_t		nat_sumd[2];
648	u_32_t		nat_ipsumd;
649	u_32_t		nat_mssclamp;
650	i6addr_t	nat_inip6;
651	i6addr_t	nat_outip6;
652	i6addr_t	nat_oip6;
653	U_QUAD_T	nat_pkts[2];
654	U_QUAD_T	nat_bytes[2];
655	union	{
656		udpinfo_t	nat_unu;
657		tcpinfo4_t	nat_unt;
658		icmpinfo_t	nat_uni;
659		greinfo_t	nat_ugre;
660	} nat_un;
661	u_short		nat_oport;
662	u_short		nat_use;
663	u_char		nat_p;
664	int		nat_dir;
665	int		nat_ref;
666	int		nat_hv[2];
667	char		nat_ifnames[2][LIFNAMSIZ];
668	int		nat_rev;
669	int		nat_redir;
670	u_32_t		nat_seqnext[2];
671} nat_4_1_25_t;
672
673typedef	struct	nat_4_1_14	{
674	ipfmutex_t	nat_lock;
675	struct	nat	*nat_next;
676	struct	nat	**nat_pnext;
677	struct	nat	*nat_hnext[2];
678	struct	nat	**nat_phnext[2];
679	struct	hostmap	*nat_hm;
680	void		*nat_data;
681	struct	nat	**nat_me;
682	struct	ipstate	*nat_state;
683	struct	ap_session	*nat_aps;
684	frentry_t	*nat_fr;
685	struct	ipnat	*nat_ptr;
686	void		*nat_ifps[2];
687	void		*nat_sync;
688	ipftqent_t	nat_tqe;
689	u_32_t		nat_flags;
690	u_32_t		nat_sumd[2];
691	u_32_t		nat_ipsumd;
692	u_32_t		nat_mssclamp;
693	i6addr_t	nat_inip6;
694	i6addr_t	nat_outip6;
695	i6addr_t	nat_oip6;
696	U_QUAD_T	nat_pkts[2];
697	U_QUAD_T	nat_bytes[2];
698	union	{
699		udpinfo_t	nat_unu;
700		tcpinfo4_t	nat_unt;
701		icmpinfo_t	nat_uni;
702		greinfo_t	nat_ugre;
703	} nat_un;
704	u_short		nat_oport;
705	u_short		nat_use;
706	u_char		nat_p;
707	int		nat_dir;
708	int		nat_ref;
709	int		nat_hv[2];
710	char		nat_ifnames[2][LIFNAMSIZ];
711	int		nat_rev;
712	int		nat_redir;
713} nat_4_1_14_t;
714
715typedef	struct	nat_4_1_3	{
716	ipfmutex_t	nat_lock;
717	struct	nat	*nat_next;
718	struct	nat	**nat_pnext;
719	struct	nat	*nat_hnext[2];
720	struct	nat	**nat_phnext[2];
721	struct	hostmap	*nat_hm;
722	void		*nat_data;
723	struct	nat	**nat_me;
724	struct	ipstate	*nat_state;
725	struct	ap_session	*nat_aps;
726	frentry_t	*nat_fr;
727	struct	ipnat	*nat_ptr;
728	void		*nat_ifps[2];
729	void		*nat_sync;
730	ipftqent_t	nat_tqe;
731	u_32_t		nat_flags;
732	u_32_t		nat_sumd[2];
733	u_32_t		nat_ipsumd;
734	u_32_t		nat_mssclamp;
735	i6addr_t	nat_inip6;
736	i6addr_t	nat_outip6;
737	i6addr_t	nat_oip6;
738	U_QUAD_T	nat_pkts[2];
739	U_QUAD_T	nat_bytes[2];
740	union	{
741		udpinfo_t	nat_unu;
742		tcpinfo4_t	nat_unt;
743		icmpinfo_t	nat_uni;
744		greinfo_t	nat_ugre;
745	} nat_un;
746	u_short		nat_oport;
747	u_short		nat_use;
748	u_char		nat_p;
749	int		nat_dir;
750	int		nat_ref;
751	int		nat_hv[2];
752	char		nat_ifnames[2][LIFNAMSIZ];
753	int		nat_rev;
754} nat_4_1_3_t;
755
756
757
758typedef struct  nat_save_4_1_34    {
759	void			*ipn_next;
760	struct	nat_4_1_25	ipn_nat;
761	struct	ipnat_4_1_14	ipn_ipnat;
762	struct	frentry_4_1_34 	ipn_fr;
763	int			ipn_dsize;
764	char			ipn_data[4];
765} nat_save_4_1_34_t;
766
767typedef	struct	nat_save_4_1_16	{
768	void		*ipn_next;
769	nat_4_1_14_t	ipn_nat;
770	ipnat_t		ipn_ipnat;
771	frentry_4_1_16_t	ipn_fr;
772	int		ipn_dsize;
773	char		ipn_data[4];
774} nat_save_4_1_16_t;
775
776typedef	struct	nat_save_4_1_14	{
777	void		*ipn_next;
778	nat_4_1_14_t	ipn_nat;
779	ipnat_t		ipn_ipnat;
780	frentry_4_1_0_t	ipn_fr;
781	int		ipn_dsize;
782	char		ipn_data[4];
783} nat_save_4_1_14_t;
784
785typedef	struct	nat_save_4_1_3	{
786	void		*ipn_next;
787	nat_4_1_3_t	ipn_nat;
788	ipnat_4_1_0_t	ipn_ipnat;
789	frentry_4_1_0_t	ipn_fr;
790	int		ipn_dsize;
791	char		ipn_data[4];
792} nat_save_4_1_3_t;
793
794/* ------------------------------------------------------------------------ */
795
796/*
797 * 5.1.0  new release (current)
798 * 4.1.32 added ns_uncreate
799 * 4.1.27 added ns_orphans
800 * 4.1.16 added ns_ticks
801 */
802typedef	struct	natstat_4_1_32	{
803	u_long	ns_mapped[2];
804	u_long	ns_rules;
805	u_long	ns_added;
806	u_long	ns_expire;
807	u_long	ns_inuse;
808	u_long	ns_logged;
809	u_long	ns_logfail;
810	u_long	ns_memfail;
811	u_long	ns_badnat;
812	u_long	ns_addtrpnt;
813	nat_t	**ns_table[2];
814	hostmap_t **ns_maptable;
815	ipnat_t	*ns_list;
816	void	*ns_apslist;
817	u_int	ns_wilds;
818	u_int	ns_nattab_sz;
819	u_int	ns_nattab_max;
820	u_int	ns_rultab_sz;
821	u_int	ns_rdrtab_sz;
822	u_int	ns_trpntab_sz;
823	u_int	ns_hostmap_sz;
824	nat_t	*ns_instances;
825	hostmap_t *ns_maplist;
826	u_long	*ns_bucketlen[2];
827	u_long	ns_ticks;
828	u_int	ns_orphans;
829	u_long	ns_uncreate[2][2];
830} natstat_4_1_32_t;
831
832typedef struct  natstat_4_1_27 {
833	u_long	ns_mapped[2];
834	u_long	ns_rules;
835	u_long	ns_added;
836	u_long	ns_expire;
837	u_long	ns_inuse;
838	u_long	ns_logged;
839	u_long	ns_logfail;
840	u_long	ns_memfail;
841	u_long	ns_badnat;
842	u_long	ns_addtrpnt;
843	nat_t	**ns_table[2];
844	hostmap_t **ns_maptable;
845	ipnat_t *ns_list;
846	void    *ns_apslist;
847	u_int   ns_wilds;
848	u_int   ns_nattab_sz;
849	u_int   ns_nattab_max;
850	u_int   ns_rultab_sz;
851	u_int   ns_rdrtab_sz;
852	u_int   ns_trpntab_sz;
853	u_int   ns_hostmap_sz;
854	nat_t   *ns_instances;
855	hostmap_t *ns_maplist;
856	u_long  *ns_bucketlen[2];
857	u_long  ns_ticks;
858	u_int   ns_orphans;
859} natstat_4_1_27_t;
860
861typedef struct  natstat_4_1_16 {
862	u_long	ns_mapped[2];
863	u_long	ns_rules;
864	u_long	ns_added;
865	u_long	ns_expire;
866	u_long	ns_inuse;
867	u_long	ns_logged;
868	u_long	ns_logfail;
869	u_long	ns_memfail;
870	u_long	ns_badnat;
871	u_long	ns_addtrpnt;
872	nat_t	**ns_table[2];
873	hostmap_t **ns_maptable;
874	ipnat_t *ns_list;
875	void    *ns_apslist;
876	u_int   ns_wilds;
877	u_int   ns_nattab_sz;
878	u_int   ns_nattab_max;
879	u_int   ns_rultab_sz;
880	u_int   ns_rdrtab_sz;
881	u_int   ns_trpntab_sz;
882	u_int   ns_hostmap_sz;
883	nat_t   *ns_instances;
884	hostmap_t *ns_maplist;
885	u_long  *ns_bucketlen[2];
886	u_long  ns_ticks;
887} natstat_4_1_16_t;
888
889typedef struct  natstat_4_1_0 {
890	u_long	ns_mapped[2];
891	u_long	ns_rules;
892	u_long	ns_added;
893	u_long	ns_expire;
894	u_long	ns_inuse;
895	u_long	ns_logged;
896	u_long	ns_logfail;
897	u_long	ns_memfail;
898	u_long	ns_badnat;
899	u_long	ns_addtrpnt;
900	nat_t	**ns_table[2];
901	hostmap_t **ns_maptable;
902	ipnat_t *ns_list;
903	void    *ns_apslist;
904	u_int   ns_wilds;
905	u_int   ns_nattab_sz;
906	u_int   ns_nattab_max;
907	u_int   ns_rultab_sz;
908	u_int   ns_rdrtab_sz;
909	u_int   ns_trpntab_sz;
910	u_int   ns_hostmap_sz;
911	nat_t   *ns_instances;
912	hostmap_t *ns_maplist;
913	u_long  *ns_bucketlen[2];
914} natstat_4_1_0_t;
915
916/* ------------------------------------------------------------------------ */
917
918/*
919 * 5.1.0  new release (current)
920 * 4.1.32 fra_info:removed both fin_state & fin_nat, added fin_pktnum
921 * 4.1.29 added fra_flx
922 * 4.1.24 fra_info:added fin_cksum
923 * 4.1.23 fra_info:added fin_exthdr
924 * 4.1.11 fra_info:added fin_ifname
925 * 4.1.4  fra_info:added fin_hbuf
926 */
927
928typedef struct  frauth_4_1_32 {
929	int	fra_age;
930	int	fra_len;
931	int	fra_index;
932	u_32_t	fra_pass;
933	fr_info_4_1_32_t	fra_info;
934	char	*fra_buf;
935	u_32_t	fra_flx;
936#if SOLARIS
937	queue_t	*fra_q;
938	mb_t	*fra_m;
939#endif
940} frauth_4_1_32_t;
941
942typedef struct  frauth_4_1_29 {
943	int	fra_age;
944	int	fra_len;
945	int	fra_index;
946	u_32_t	fra_pass;
947	fr_info_4_1_24_t	fra_info;
948	char	*fra_buf;
949	u_32_t	fra_flx;
950#if SOLARIS
951	queue_t	*fra_q;
952	mb_t	*fra_m;
953#endif
954} frauth_4_1_29_t;
955
956typedef struct  frauth_4_1_24 {
957	int	fra_age;
958	int	fra_len;
959	int	fra_index;
960	u_32_t	fra_pass;
961	fr_info_4_1_24_t	fra_info;
962	char	*fra_buf;
963#if SOLARIS
964	queue_t	*fra_q;
965	mb_t	*fra_m;
966#endif
967} frauth_4_1_24_t;
968
969typedef struct  frauth_4_1_23 {
970	int	fra_age;
971	int	fra_len;
972	int	fra_index;
973	u_32_t	fra_pass;
974	fr_info_4_1_23_t	fra_info;
975	char	*fra_buf;
976#if SOLARIS
977	queue_t	*fra_q;
978	mb_t	*fra_m;
979#endif
980} frauth_4_1_23_t;
981
982typedef struct  frauth_4_1_11 {
983	int	fra_age;
984	int	fra_len;
985	int	fra_index;
986	u_32_t	fra_pass;
987	fr_info_4_1_11_t	fra_info;
988	char	*fra_buf;
989#if SOLARIS
990	queue_t	*fra_q;
991	mb_t	*fra_m;
992#endif
993} frauth_4_1_11_t;
994
995/* ------------------------------------------------------------------------ */
996
997/*
998 * 5.1.0  new release (current)
999 * 4.1.16 removed is_nat
1000 */
1001typedef struct ipstate_4_1_16 {
1002	ipfmutex_t	is_lock;
1003	struct	ipstate	*is_next;
1004	struct	ipstate	**is_pnext;
1005	struct	ipstate	*is_hnext;
1006	struct	ipstate	**is_phnext;
1007	struct	ipstate	**is_me;
1008	void		*is_ifp[4];
1009	void		*is_sync;
1010	frentry_t	*is_rule;
1011	struct	ipftq	*is_tqehead[2];
1012	struct	ipscan	*is_isc;
1013	U_QUAD_T	is_pkts[4];
1014	U_QUAD_T	is_bytes[4];
1015	U_QUAD_T	is_icmppkts[4];
1016	struct	ipftqent is_sti;
1017	u_int	is_frage[2];
1018	int	is_ref;			/* reference count */
1019	int	is_isninc[2];
1020	u_short	is_sumd[2];
1021	i6addr_t	is_src;
1022	i6addr_t	is_dst;
1023	u_int	is_pass;
1024	u_char	is_p;			/* Protocol */
1025	u_char	is_v;
1026	u_32_t	is_hv;
1027	u_32_t	is_tag;
1028	u_32_t	is_opt[2];		/* packet options set */
1029	u_32_t	is_optmsk[2];		/*    "      "    mask */
1030	u_short	is_sec;			/* security options set */
1031	u_short	is_secmsk;		/*    "        "    mask */
1032	u_short	is_auth;		/* authentication options set */
1033	u_short	is_authmsk;		/*    "              "    mask */
1034	union {
1035		icmpinfo_t	is_ics;
1036		tcpinfo4_t	is_ts;
1037		udpinfo_t	is_us;
1038		greinfo_t	is_ug;
1039	} is_ps;
1040	u_32_t	is_flags;
1041	int	is_flx[2][2];
1042	u_32_t	is_rulen;		/* rule number when created */
1043	u_32_t	is_s0[2];
1044	u_short	is_smsk[2];
1045	char	is_group[FR_GROUPLEN];
1046	char	is_sbuf[2][16];
1047	char	is_ifname[4][LIFNAMSIZ];
1048} ipstate_4_1_16_t;
1049
1050typedef struct ipstate_4_1_0 {
1051	ipfmutex_t	is_lock;
1052	struct	ipstate	*is_next;
1053	struct	ipstate	**is_pnext;
1054	struct	ipstate	*is_hnext;
1055	struct	ipstate	**is_phnext;
1056	struct	ipstate	**is_me;
1057	void		*is_ifp[4];
1058	void		*is_sync;
1059	void		*is_nat[2];
1060	frentry_t	*is_rule;
1061	struct	ipftq	*is_tqehead[2];
1062	struct	ipscan	*is_isc;
1063	U_QUAD_T	is_pkts[4];
1064	U_QUAD_T	is_bytes[4];
1065	U_QUAD_T	is_icmppkts[4];
1066	struct	ipftqent is_sti;
1067	u_int	is_frage[2];
1068	int	is_ref;
1069	int	is_isninc[2];
1070	u_short	is_sumd[2];
1071	i6addr_t	is_src;
1072	i6addr_t	is_dst;
1073	u_int	is_pass;
1074	u_char	is_p;
1075	u_char	is_v;
1076	u_32_t	is_hv;
1077	u_32_t	is_tag;
1078	u_32_t	is_opt[2];
1079	u_32_t	is_optmsk[2];
1080	u_short	is_sec;
1081	u_short	is_secmsk;
1082	u_short	is_auth;
1083	u_short	is_authmsk;
1084	union {
1085		icmpinfo_t	is_ics;
1086		tcpinfo4_t	is_ts;
1087		udpinfo_t	is_us;
1088		greinfo_t	is_ug;
1089	} is_ps;
1090	u_32_t	is_flags;
1091	int	is_flx[2][2];
1092	u_32_t	is_rulen;
1093	u_32_t	is_s0[2];
1094	u_short	is_smsk[2];
1095	char	is_group[FR_GROUPLEN];
1096	char	is_sbuf[2][16];
1097	char	is_ifname[4][LIFNAMSIZ];
1098} ipstate_4_1_0_t;
1099
1100typedef	struct	ipstate_save_4_1_34	{
1101	void	*ips_next;
1102	struct	ipstate_4_1_16	ips_is;
1103	struct	frentry_4_1_34	ips_fr;
1104} ipstate_save_4_1_34_t;
1105
1106typedef	struct	ipstate_save_4_1_16	{
1107	void		*ips_next;
1108	ipstate_4_1_0_t	ips_is;
1109	frentry_4_1_16_t	ips_fr;
1110} ipstate_save_4_1_16_t;
1111
1112typedef	struct	ipstate_save_4_1_0	{
1113	void		*ips_next;
1114	ipstate_4_1_0_t	ips_is;
1115	frentry_4_1_0_t	ips_fr;
1116} ipstate_save_4_1_0_t;
1117
1118/* ------------------------------------------------------------------------ */
1119
1120/*
1121 * 5.1.0  new release (current)
1122 * 4.1.21 added iss_tcptab
1123 */
1124typedef	struct	ips_stat_4_1_21 {
1125	u_long	iss_hits;
1126	u_long	iss_miss;
1127	u_long	iss_max;
1128	u_long	iss_maxref;
1129	u_long	iss_tcp;
1130	u_long	iss_udp;
1131	u_long	iss_icmp;
1132	u_long	iss_nomem;
1133	u_long	iss_expire;
1134	u_long	iss_fin;
1135	u_long	iss_active;
1136	u_long	iss_logged;
1137	u_long	iss_logfail;
1138	u_long	iss_inuse;
1139	u_long	iss_wild;
1140	u_long	iss_killed;
1141	u_long	iss_ticks;
1142	u_long	iss_bucketfull;
1143	int	iss_statesize;
1144	int	iss_statemax;
1145	ipstate_t **iss_table;
1146	ipstate_t *iss_list;
1147	u_long	*iss_bucketlen;
1148	ipftq_t	*iss_tcptab;
1149} ips_stat_4_1_21_t;
1150
1151typedef	struct	ips_stat_4_1_0 {
1152	u_long	iss_hits;
1153	u_long	iss_miss;
1154	u_long	iss_max;
1155	u_long	iss_maxref;
1156	u_long	iss_tcp;
1157	u_long	iss_udp;
1158	u_long	iss_icmp;
1159	u_long	iss_nomem;
1160	u_long	iss_expire;
1161	u_long	iss_fin;
1162	u_long	iss_active;
1163	u_long	iss_logged;
1164	u_long	iss_logfail;
1165	u_long	iss_inuse;
1166	u_long	iss_wild;
1167	u_long	iss_killed;
1168	u_long	iss_ticks;
1169	u_long	iss_bucketfull;
1170	int	iss_statesize;
1171	int	iss_statemax;
1172	ipstate_t **iss_table;
1173	ipstate_t *iss_list;
1174	u_long	*iss_bucketlen;
1175} ips_stat_4_1_0_t;
1176
1177/* ------------------------------------------------------------------------ */
1178
1179typedef	struct	ipfrstat_4_1_1 {
1180	u_long	ifs_exists;	/* add & already exists */
1181	u_long	ifs_nomem;
1182	u_long	ifs_new;
1183	u_long	ifs_hits;
1184	u_long	ifs_expire;
1185	u_long	ifs_inuse;
1186	u_long	ifs_retrans0;
1187	u_long	ifs_short;
1188	struct	ipfr	**ifs_table;
1189	struct	ipfr	**ifs_nattab;
1190} ipfrstat_4_1_1_t;
1191
1192/* ------------------------------------------------------------------------ */
1193static int ipf_addfrstr(char *, int, char *, int);
1194static void ipf_v4iptov5(frip4_t *, fr_ip_t *);
1195static void ipf_v5iptov4(fr_ip_t *, frip4_t *);
1196static void ipfv4tuctov5(frtuc4_t *, frtuc_t *);
1197static void ipfv5tuctov4(frtuc_t *, frtuc4_t *);
1198static int ipf_v4fripftov5(fripf4_t *, char *);
1199static void ipf_v5fripftov4(fripf_t *, fripf4_t *);
1200static int fr_frflags4to5(u_32_t);
1201static int fr_frflags5to4(u_32_t);
1202
1203static void friostat_current_to_4_1_0(void *, friostat_4_1_0_t *, int);
1204static void friostat_current_to_4_1_33(void *, friostat_4_1_33_t *, int);
1205static void ipstate_current_to_4_1_0(void *, ipstate_4_1_0_t *);
1206static void ipstate_current_to_4_1_16(void *, ipstate_4_1_16_t *);
1207static void ipnat_current_to_4_1_0(void *, ipnat_4_1_0_t *);
1208static void ipnat_current_to_4_1_14(void *, ipnat_4_1_14_t *);
1209static void frauth_current_to_4_1_11(void *, frauth_4_1_11_t *);
1210static void frauth_current_to_4_1_23(void *, frauth_4_1_23_t *);
1211static void frauth_current_to_4_1_24(void *, frauth_4_1_24_t *);
1212static void frauth_current_to_4_1_29(void *, frauth_4_1_29_t *);
1213static void frentry_current_to_4_1_0(void *, frentry_4_1_0_t *);
1214static void frentry_current_to_4_1_16(void *, frentry_4_1_16_t *);
1215static void frentry_current_to_4_1_34(void *, frentry_4_1_34_t *);
1216static void fr_info_current_to_4_1_11(void *, fr_info_4_1_11_t *);
1217static void fr_info_current_to_4_1_23(void *, fr_info_4_1_23_t *);
1218static void fr_info_current_to_4_1_24(void *, fr_info_4_1_24_t *);
1219static void nat_save_current_to_4_1_3(void *, nat_save_4_1_3_t *);
1220static void nat_save_current_to_4_1_14(void *, nat_save_4_1_14_t *);
1221static void nat_save_current_to_4_1_16(void *, nat_save_4_1_16_t *);
1222static void ipstate_save_current_to_4_1_0(void *, ipstate_save_4_1_0_t *);
1223static void ipstate_save_current_to_4_1_16(void *, ipstate_save_4_1_16_t *);
1224static void ips_stat_current_to_4_1_0(void *, ips_stat_4_1_0_t *);
1225static void ips_stat_current_to_4_1_21(void *, ips_stat_4_1_21_t *);
1226static void natstat_current_to_4_1_0(void *, natstat_4_1_0_t *);
1227static void natstat_current_to_4_1_16(void *, natstat_4_1_16_t *);
1228static void natstat_current_to_4_1_27(void *, natstat_4_1_27_t *);
1229static void natstat_current_to_4_1_32(void *, natstat_4_1_32_t *);
1230static void nat_current_to_4_1_3(void *, nat_4_1_3_t *);
1231static void nat_current_to_4_1_14(void *, nat_4_1_14_t *);
1232static void nat_current_to_4_1_25(void *, nat_4_1_25_t *);
1233
1234static void friostat_4_1_0_to_current(friostat_4_1_0_t *, void *);
1235static void friostat_4_1_33_to_current(friostat_4_1_33_t *, void *);
1236static void ipnat_4_1_0_to_current(ipnat_4_1_0_t *, void *, int);
1237static void ipnat_4_1_14_to_current(ipnat_4_1_14_t *, void *, int);
1238static void frauth_4_1_11_to_current(frauth_4_1_11_t *, void *);
1239static void frauth_4_1_23_to_current(frauth_4_1_23_t *, void *);
1240static void frauth_4_1_24_to_current(frauth_4_1_24_t *, void *);
1241static void frauth_4_1_29_to_current(frauth_4_1_29_t *, void *);
1242static void frauth_4_1_32_to_current(frauth_4_1_32_t *, void *);
1243static void frentry_4_1_0_to_current(ipf_main_softc_t *, frentry_4_1_0_t *, void *, int);
1244static void frentry_4_1_16_to_current(ipf_main_softc_t *, frentry_4_1_16_t *, void *, int);
1245static void frentry_4_1_34_to_current(ipf_main_softc_t *, frentry_4_1_34_t *, void *, int);
1246static void fr_info_4_1_11_to_current(fr_info_4_1_11_t *, void *);
1247static void fr_info_4_1_23_to_current(fr_info_4_1_23_t *, void *);
1248static void fr_info_4_1_24_to_current(fr_info_4_1_24_t *, void *);
1249static void fr_info_4_1_32_to_current(fr_info_4_1_32_t *, void *);
1250static void nat_save_4_1_3_to_current(ipf_main_softc_t *, nat_save_4_1_3_t *, void *);
1251static void nat_save_4_1_14_to_current(ipf_main_softc_t *, nat_save_4_1_14_t *, void *);
1252static void nat_save_4_1_16_to_current(ipf_main_softc_t *, nat_save_4_1_16_t *, void *);
1253
1254/* ------------------------------------------------------------------------ */
1255/* In this section is a series of short routines that deal with translating */
1256/* the smaller data structures used above as their internal changes make    */
1257/* them inappropriate for simple assignment.                                */
1258/* ------------------------------------------------------------------------ */
1259
1260
1261static int
1262ipf_addfrstr(char *names, int namelen, char *str, int maxlen)
1263{
1264	char *t;
1265	int i;
1266
1267	for (i = maxlen, t = str; (*t != '\0') && (i > 0); i--) {
1268		names[namelen++] = *t++;
1269	}
1270	names[namelen++] = '\0';
1271	return namelen;
1272}
1273
1274
1275static void
1276ipf_v4iptov5(v4, v5)
1277	frip4_t *v4;
1278	fr_ip_t *v5;
1279{
1280	v5->fi_v = v4->fi_v;
1281	v5->fi_p = v4->fi_p;
1282	v5->fi_xx = v4->fi_xx;
1283	v5->fi_tos = v4->fi_tos;
1284	v5->fi_ttl = v4->fi_ttl;
1285	v5->fi_p = v4->fi_p;
1286	v5->fi_optmsk = v4->fi_optmsk;
1287	v5->fi_src = v4->fi_src;
1288	v5->fi_dst = v4->fi_dst;
1289	v5->fi_secmsk = v4->ofi_secmsk;
1290	v5->fi_auth = v4->ofi_auth;
1291	v5->fi_flx = v4->fi_flx;
1292	v5->fi_tcpmsk = v4->fi_tcpmsk;
1293}
1294
1295static void
1296ipf_v5iptov4(v5, v4)
1297	fr_ip_t *v5;
1298	frip4_t *v4;
1299{
1300	v4->fi_v = v5->fi_v;
1301	v4->fi_p = v5->fi_p;
1302	v4->fi_xx = v5->fi_xx;
1303	v4->fi_tos = v5->fi_tos;
1304	v4->fi_ttl = v5->fi_ttl;
1305	v4->fi_p = v5->fi_p;
1306	v4->fi_optmsk = v5->fi_optmsk;
1307	v4->fi_src = v5->fi_src;
1308	v4->fi_dst = v5->fi_dst;
1309	v4->ofi_secmsk = v5->fi_secmsk;
1310	v4->ofi_auth = v5->fi_auth;
1311	v4->fi_flx = v5->fi_flx;
1312	v4->fi_tcpmsk = v5->fi_tcpmsk;
1313}
1314
1315
1316static void
1317ipfv4tuctov5(v4, v5)
1318	frtuc4_t *v4;
1319	frtuc_t *v5;
1320{
1321	v5->ftu_src.frp_cmp = v4->ftu_src.frp_cmp;
1322	v5->ftu_src.frp_port = v4->ftu_src.frp_port;
1323	v5->ftu_src.frp_top = v4->ftu_src.frp_top;
1324	v5->ftu_dst.frp_cmp = v4->ftu_dst.frp_cmp;
1325	v5->ftu_dst.frp_port = v4->ftu_dst.frp_port;
1326	v5->ftu_dst.frp_top = v4->ftu_dst.frp_top;
1327}
1328
1329
1330static void
1331ipfv5tuctov4(v5, v4)
1332	frtuc_t *v5;
1333	frtuc4_t *v4;
1334{
1335	v4->ftu_src.frp_cmp = v5->ftu_src.frp_cmp;
1336	v4->ftu_src.frp_port = v5->ftu_src.frp_port;
1337	v4->ftu_src.frp_top = v5->ftu_src.frp_top;
1338	v4->ftu_dst.frp_cmp = v5->ftu_dst.frp_cmp;
1339	v4->ftu_dst.frp_port = v5->ftu_dst.frp_port;
1340	v4->ftu_dst.frp_top = v5->ftu_dst.frp_top;
1341}
1342
1343
1344static int
1345ipf_v4fripftov5(frp4, dst)
1346	fripf4_t *frp4;
1347	char *dst;
1348{
1349	fripf_t *frp;
1350
1351	frp = (fripf_t *)dst;
1352
1353	ipf_v4iptov5(&frp4->fri_ip, &frp->fri_ip);
1354	ipf_v4iptov5(&frp4->fri_mip, &frp->fri_mip);
1355	frp->fri_icmpm = frp4->fri_icmpm;
1356	frp->fri_icmp = frp4->fri_icmp;
1357	frp->fri_tuc.ftu_tcpfm = frp4->fri_tuc.ftu_tcpfm;
1358	frp->fri_tuc.ftu_tcpf = frp4->fri_tuc.ftu_tcpf;
1359	ipfv4tuctov5(&frp4->fri_tuc, &frp->fri_tuc);
1360	frp->fri_satype = frp4->fri_satype;
1361	frp->fri_datype = frp4->fri_datype;
1362	frp->fri_sifpidx = frp4->fri_sifpidx;
1363	frp->fri_difpidx = frp4->fri_difpidx;
1364	return 0;
1365}
1366
1367
1368static void
1369ipf_v5fripftov4(frp, frp4)
1370	fripf_t *frp;
1371	fripf4_t *frp4;
1372{
1373
1374	ipf_v5iptov4(&frp->fri_ip, &frp4->fri_ip);
1375	ipf_v5iptov4(&frp->fri_mip, &frp4->fri_mip);
1376	frp4->fri_icmpm = frp->fri_icmpm;
1377	frp4->fri_icmp = frp->fri_icmp;
1378	frp4->fri_tuc.ftu_tcpfm = frp->fri_tuc.ftu_tcpfm;
1379	frp4->fri_tuc.ftu_tcpf = frp->fri_tuc.ftu_tcpf;
1380	ipfv5tuctov4(&frp->fri_tuc, &frp4->fri_tuc);
1381	frp4->fri_satype = frp->fri_satype;
1382	frp4->fri_datype = frp->fri_datype;
1383	frp4->fri_sifpidx = frp->fri_sifpidx;
1384	frp4->fri_difpidx = frp->fri_difpidx;
1385}
1386
1387
1388/* ------------------------------------------------------------------------ */
1389/* ipf_in_compat is the first of two service routines. It is responsible for*/
1390/* converting data structures from user space into what's required by the   */
1391/* kernel module.                                                           */
1392/* ------------------------------------------------------------------------ */
1393int
1394ipf_in_compat(softc, obj, ptr, size)
1395	ipf_main_softc_t *softc;
1396	ipfobj_t *obj;
1397	void *ptr;
1398	int size;
1399{
1400	int error;
1401	int sz;
1402
1403	IPFERROR(140000);
1404	error = EINVAL;
1405
1406	switch (obj->ipfo_type)
1407	{
1408	default :
1409		break;
1410
1411	case IPFOBJ_FRENTRY :
1412		if (obj->ipfo_rev >= 4013400) {
1413			frentry_4_1_34_t *old;
1414
1415			KMALLOC(old, frentry_4_1_34_t *);
1416			if (old == NULL) {
1417				IPFERROR(140001);
1418				error = ENOMEM;
1419				break;
1420			}
1421			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1422			if (error == 0) {
1423				if (old->fr_type != FR_T_NONE &&
1424				    old->fr_type != FR_T_IPF) {
1425					IPFERROR(140002);
1426					error = EINVAL;
1427					KFREE(old);
1428					break;
1429				}
1430				frentry_4_1_34_to_current(softc, old,
1431							  ptr, size);
1432			} else {
1433				IPFERROR(140003);
1434			}
1435			KFREE(old);
1436		} else if (obj->ipfo_rev >= 4011600) {
1437			frentry_4_1_16_t *old;
1438
1439			KMALLOC(old, frentry_4_1_16_t *);
1440			if (old == NULL) {
1441				IPFERROR(140004);
1442				error = ENOMEM;
1443				break;
1444			}
1445			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1446			if (error == 0) {
1447				if (old->fr_type != FR_T_NONE &&
1448				    old->fr_type != FR_T_IPF) {
1449					IPFERROR(140005);
1450					error = EINVAL;
1451					KFREE(old);
1452					break;
1453				}
1454				frentry_4_1_16_to_current(softc, old,
1455							  ptr, size);
1456			} else {
1457				IPFERROR(140006);
1458			}
1459			KFREE(old);
1460		} else {
1461			frentry_4_1_0_t *old;
1462
1463			KMALLOC(old, frentry_4_1_0_t *);
1464			if (old == NULL) {
1465				IPFERROR(140007);
1466				error = ENOMEM;
1467				break;
1468			}
1469			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1470			if (error == 0) {
1471				if (old->fr_type != FR_T_NONE &&
1472				    old->fr_type != FR_T_IPF) {
1473					IPFERROR(140008);
1474					error = EINVAL;
1475					KFREE(old);
1476					break;
1477				}
1478				frentry_4_1_0_to_current(softc, old, ptr, size);
1479			} else {
1480				IPFERROR(140009);
1481			}
1482			KFREE(old);
1483		}
1484		break;
1485
1486	case IPFOBJ_IPFSTAT :
1487		if (obj->ipfo_rev >= 4013300) {
1488			friostat_4_1_33_t *old;
1489
1490			KMALLOC(old, friostat_4_1_33_t *);
1491			if (old == NULL) {
1492				IPFERROR(140010);
1493				error = ENOMEM;
1494				break;
1495			}
1496			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1497			if (error == 0) {
1498				friostat_4_1_33_to_current(old, ptr);
1499			} else {
1500				IPFERROR(140011);
1501			}
1502		} else {
1503			friostat_4_1_0_t *old;
1504
1505			KMALLOC(old, friostat_4_1_0_t *);
1506			if (old == NULL) {
1507				IPFERROR(140012);
1508				error = ENOMEM;
1509				break;
1510			}
1511			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1512			if (error == 0) {
1513				friostat_4_1_0_to_current(old, ptr);
1514			} else {
1515				IPFERROR(140013);
1516			}
1517		}
1518		break;
1519
1520	case IPFOBJ_IPFINFO :	/* unused */
1521		break;
1522
1523	case IPFOBJ_IPNAT :
1524		if (obj->ipfo_rev >= 4011400) {
1525			ipnat_4_1_14_t *old;
1526
1527			KMALLOC(old, ipnat_4_1_14_t *);
1528			if (old == NULL) {
1529				IPFERROR(140014);
1530				error = ENOMEM;
1531				break;
1532			}
1533			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1534			if (error == 0) {
1535				ipnat_4_1_14_to_current(old, ptr, size);
1536			} else {
1537				IPFERROR(140015);
1538			}
1539			KFREE(old);
1540		} else {
1541			ipnat_4_1_0_t *old;
1542
1543			KMALLOC(old, ipnat_4_1_0_t *);
1544			if (old == NULL) {
1545				IPFERROR(140016);
1546				error = ENOMEM;
1547				break;
1548			}
1549			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1550			if (error == 0) {
1551				ipnat_4_1_0_to_current(old, ptr, size);
1552			} else {
1553				IPFERROR(140017);
1554			}
1555			KFREE(old);
1556		}
1557		break;
1558
1559	case IPFOBJ_NATSTAT :
1560		/*
1561		 * Statistics are not copied in.
1562		 */
1563		break;
1564
1565	case IPFOBJ_NATSAVE :
1566		if (obj->ipfo_rev >= 4011600) {
1567			nat_save_4_1_16_t *old16;
1568
1569			KMALLOC(old16, nat_save_4_1_16_t *);
1570			if (old16 == NULL) {
1571				IPFERROR(140018);
1572				error = ENOMEM;
1573				break;
1574			}
1575			error = COPYIN(obj->ipfo_ptr, old16, sizeof(*old16));
1576			if (error == 0) {
1577				nat_save_4_1_16_to_current(softc, old16, ptr);
1578			} else {
1579				IPFERROR(140019);
1580			}
1581			KFREE(old16);
1582		} else if (obj->ipfo_rev >= 4011400) {
1583			nat_save_4_1_14_t *old14;
1584
1585			KMALLOC(old14, nat_save_4_1_14_t *);
1586			if (old14 == NULL) {
1587				IPFERROR(140020);
1588				error = ENOMEM;
1589				break;
1590			}
1591			error = COPYIN(obj->ipfo_ptr, old14, sizeof(*old14));
1592			if (error == 0) {
1593				nat_save_4_1_14_to_current(softc, old14, ptr);
1594			} else {
1595				IPFERROR(140021);
1596			}
1597			KFREE(old14);
1598		} else if (obj->ipfo_rev >= 4010300) {
1599			nat_save_4_1_3_t *old3;
1600
1601			KMALLOC(old3, nat_save_4_1_3_t *);
1602			if (old3 == NULL) {
1603				IPFERROR(140022);
1604				error = ENOMEM;
1605				break;
1606			}
1607			error = COPYIN(obj->ipfo_ptr, old3, sizeof(*old3));
1608			if (error == 0) {
1609				nat_save_4_1_3_to_current(softc, old3, ptr);
1610			} else {
1611				IPFERROR(140023);
1612			}
1613			KFREE(old3);
1614		}
1615		break;
1616
1617	case IPFOBJ_STATESAVE :
1618		if (obj->ipfo_rev >= 4013400) {
1619			ipstate_save_4_1_34_t *old;
1620
1621			KMALLOC(old, ipstate_save_4_1_34_t *);
1622			if (old == NULL) {
1623				IPFERROR(140024);
1624				error = ENOMEM;
1625				break;
1626			}
1627			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1628			if (error != 0) {
1629				IPFERROR(140025);
1630			}
1631			KFREE(old);
1632		} else if (obj->ipfo_rev >= 4011600) {
1633			ipstate_save_4_1_16_t *old;
1634
1635			KMALLOC(old, ipstate_save_4_1_16_t *);
1636			if (old == NULL) {
1637				IPFERROR(140026);
1638				error = ENOMEM;
1639				break;
1640			}
1641			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1642			if (error != 0) {
1643				IPFERROR(140027);
1644			}
1645			KFREE(old);
1646		} else {
1647			ipstate_save_4_1_0_t *old;
1648
1649			KMALLOC(old, ipstate_save_4_1_0_t *);
1650			if (old == NULL) {
1651				IPFERROR(140028);
1652				error = ENOMEM;
1653				break;
1654			}
1655			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1656			if (error != 0) {
1657				IPFERROR(140029);
1658			}
1659			KFREE(old);
1660		}
1661		break;
1662
1663	case IPFOBJ_IPSTATE :
1664		/*
1665		 * This structure is not copied in by itself.
1666		 */
1667		break;
1668
1669	case IPFOBJ_STATESTAT :
1670		/*
1671		 * Statistics are not copied in.
1672		 */
1673		break;
1674
1675	case IPFOBJ_FRAUTH :
1676		if (obj->ipfo_rev >= 4013200) {
1677			frauth_4_1_32_t *old32;
1678
1679			KMALLOC(old32, frauth_4_1_32_t *);
1680			if (old32 == NULL) {
1681				IPFERROR(140030);
1682				error = ENOMEM;
1683				break;
1684			}
1685			error = COPYIN(obj->ipfo_ptr, old32, sizeof(*old32));
1686			if (error == 0) {
1687				frauth_4_1_32_to_current(old32, ptr);
1688			} else {
1689				IPFERROR(140031);
1690			}
1691			KFREE(old32);
1692		} else if (obj->ipfo_rev >= 4012900) {
1693			frauth_4_1_29_t *old29;
1694
1695			KMALLOC(old29, frauth_4_1_29_t *);
1696			if (old29 == NULL) {
1697				IPFERROR(140032);
1698				error = ENOMEM;
1699				break;
1700			}
1701			error = COPYIN(obj->ipfo_ptr, old29, sizeof(*old29));
1702			if (error == 0) {
1703				frauth_4_1_29_to_current(old29, ptr);
1704			} else {
1705				IPFERROR(140033);
1706			}
1707			KFREE(old29);
1708		} else if (obj->ipfo_rev >= 4012400) {
1709			frauth_4_1_24_t *old24;
1710
1711			KMALLOC(old24, frauth_4_1_24_t *);
1712			if (old24 == NULL) {
1713				IPFERROR(140034);
1714				error = ENOMEM;
1715				break;
1716			}
1717			error = COPYIN(obj->ipfo_ptr, old24, sizeof(*old24));
1718			if (error == 0) {
1719				frauth_4_1_24_to_current(old24, ptr);
1720			} else {
1721				IPFERROR(140035);
1722			}
1723			KFREE(old24);
1724		} else if (obj->ipfo_rev >= 4012300) {
1725			frauth_4_1_23_t *old23;
1726
1727			KMALLOC(old23, frauth_4_1_23_t *);
1728			if (old23 == NULL) {
1729				IPFERROR(140036);
1730				error = ENOMEM;
1731				break;
1732			}
1733			error = COPYIN(obj->ipfo_ptr, old23, sizeof(*old23));
1734			if (error == 0)
1735				frauth_4_1_23_to_current(old23, ptr);
1736			KFREE(old23);
1737		} else if (obj->ipfo_rev >= 4011100) {
1738			frauth_4_1_11_t *old11;
1739
1740			KMALLOC(old11, frauth_4_1_11_t *);
1741			if (old11 == NULL) {
1742				IPFERROR(140037);
1743				error = ENOMEM;
1744				break;
1745			}
1746			error = COPYIN(obj->ipfo_ptr, old11, sizeof(*old11));
1747			if (error == 0) {
1748				frauth_4_1_11_to_current(old11, ptr);
1749			} else {
1750				IPFERROR(140038);
1751			}
1752			KFREE(old11);
1753		}
1754		break;
1755
1756	case IPFOBJ_NAT :
1757		if (obj->ipfo_rev >= 4011400) {
1758			sz = sizeof(nat_4_1_14_t);
1759		} else if (obj->ipfo_rev >= 4010300) {
1760			sz = sizeof(nat_4_1_3_t);
1761		} else {
1762			break;
1763		}
1764		bzero(ptr, sizeof(nat_t));
1765		error = COPYIN(obj->ipfo_ptr, ptr, sz);
1766		if (error != 0) {
1767			IPFERROR(140039);
1768		}
1769		break;
1770
1771	case IPFOBJ_FRIPF :
1772		if (obj->ipfo_rev < 5000000) {
1773			fripf4_t *old;
1774
1775			KMALLOC(old, fripf4_t *);
1776			if (old == NULL) {
1777				IPFERROR(140040);
1778				error = ENOMEM;
1779				break;
1780			}
1781			error = COPYIN(obj->ipfo_ptr, old, sizeof(*old));
1782			if (error == 0) {
1783				ipf_v4fripftov5(old, ptr);
1784			} else {
1785				IPFERROR(140041);
1786			}
1787			KFREE(old);
1788		}
1789		break;
1790	}
1791
1792	return error;
1793}
1794/* ------------------------------------------------------------------------ */
1795
1796
1797/*
1798 * flags is v4 flags, returns v5 flags.
1799 */
1800static int
1801fr_frflags4to5(flags)
1802	u_32_t flags;
1803{
1804	u_32_t nflags = 0;
1805
1806	switch (flags & 0xf) {
1807	case 0x0 :
1808		nflags |= FR_CALL;
1809		break;
1810	case 0x1 :
1811		nflags |= FR_BLOCK;
1812		break;
1813	case 0x2 :
1814		nflags |= FR_PASS;
1815		break;
1816	case 0x3 :
1817		nflags |= FR_AUTH;
1818		break;
1819	case 0x4 :
1820		nflags |= FR_PREAUTH;
1821		break;
1822	case 0x5 :
1823		nflags |= FR_ACCOUNT;
1824		break;
1825	case 0x6 :
1826		nflags |= FR_SKIP;
1827		break;
1828	default :
1829		break;
1830	}
1831
1832	if (flags & 0x00010)
1833		nflags |= FR_LOG;
1834	if (flags & 0x00020)
1835		nflags |= FR_CALLNOW;
1836	if (flags & 0x00080)
1837		nflags |= FR_NOTSRCIP;
1838	if (flags & 0x00040)
1839		nflags |= FR_NOTDSTIP;
1840	if (flags & 0x00100)
1841		nflags |= FR_QUICK;
1842	if (flags & 0x00200)
1843		nflags |= FR_KEEPFRAG;
1844	if (flags & 0x00400)
1845		nflags |= FR_KEEPSTATE;
1846	if (flags & 0x00800)
1847		nflags |= FR_FASTROUTE;
1848	if (flags & 0x01000)
1849		nflags |= FR_RETRST;
1850	if (flags & 0x02000)
1851		nflags |= FR_RETICMP;
1852	if (flags & 0x03000)
1853		nflags |= FR_FAKEICMP;
1854	if (flags & 0x04000)
1855		nflags |= FR_OUTQUE;
1856	if (flags & 0x08000)
1857		nflags |= FR_INQUE;
1858	if (flags & 0x10000)
1859		nflags |= FR_LOGBODY;
1860	if (flags & 0x20000)
1861		nflags |= FR_LOGFIRST;
1862	if (flags & 0x40000)
1863		nflags |= FR_LOGORBLOCK;
1864	if (flags & 0x100000)
1865		nflags |= FR_FRSTRICT;
1866	if (flags & 0x200000)
1867		nflags |= FR_STSTRICT;
1868	if (flags & 0x400000)
1869		nflags |= FR_NEWISN;
1870	if (flags & 0x800000)
1871		nflags |= FR_NOICMPERR;
1872	if (flags & 0x1000000)
1873		nflags |= FR_STATESYNC;
1874	if (flags & 0x8000000)
1875		nflags |= FR_NOMATCH;
1876	if (flags & 0x40000000)
1877		nflags |= FR_COPIED;
1878	if (flags & 0x80000000)
1879		nflags |= FR_INACTIVE;
1880
1881	return nflags;
1882}
1883
1884static void
1885frentry_4_1_34_to_current(softc, old, current, size)
1886	ipf_main_softc_t *softc;
1887	frentry_4_1_34_t *old;
1888	void *current;
1889	int size;
1890{
1891	frentry_t *fr = (frentry_t *)current;
1892
1893	fr->fr_comment = -1;
1894	fr->fr_ref = old->fr_ref;
1895	fr->fr_statecnt = old->fr_statecnt;
1896	fr->fr_hits = old->fr_hits;
1897	fr->fr_bytes = old->fr_bytes;
1898	fr->fr_lastpkt.tv_sec = old->fr_lastpkt.tv_sec;
1899	fr->fr_lastpkt.tv_usec = old->fr_lastpkt.tv_usec;
1900	bcopy(&old->fr_dun, &fr->fr_dun, sizeof(old->fr_dun));
1901	fr->fr_func = old->fr_func;
1902	fr->fr_dsize = old->fr_dsize;
1903	fr->fr_pps = old->fr_pps;
1904	fr->fr_statemax = old->fr_statemax;
1905	fr->fr_flineno = old->fr_flineno;
1906	fr->fr_type = old->fr_type;
1907	fr->fr_flags = fr_frflags4to5(old->fr_flags);
1908	fr->fr_logtag = old->fr_logtag;
1909	fr->fr_collect = old->fr_collect;
1910	fr->fr_arg = old->fr_arg;
1911	fr->fr_loglevel = old->fr_loglevel;
1912	fr->fr_age[0] = old->fr_age[0];
1913	fr->fr_age[1] = old->fr_age[1];
1914	fr->fr_tifs[0].fd_ip6 = old->fr_tifs[0].ofd_ip6;
1915	fr->fr_tifs[0].fd_type = FRD_NORMAL;
1916	fr->fr_tifs[1].fd_ip6 = old->fr_tifs[1].ofd_ip6;
1917	fr->fr_tifs[1].fd_type = FRD_NORMAL;
1918	fr->fr_dif.fd_ip6 = old->fr_dif.ofd_ip6;
1919	fr->fr_dif.fd_type = FRD_NORMAL;
1920	if (old->fr_v == 4)
1921		fr->fr_family = AF_INET;
1922	if (old->fr_v == 6)
1923		fr->fr_family = AF_INET6;
1924	fr->fr_icode = old->fr_icode;
1925	fr->fr_cksum = old->fr_cksum;
1926	fr->fr_namelen = 0;
1927	fr->fr_ifnames[0] = -1;
1928	fr->fr_ifnames[1] = -1;
1929	fr->fr_ifnames[2] = -1;
1930	fr->fr_ifnames[3] = -1;
1931	fr->fr_dif.fd_name = -1;
1932	fr->fr_tifs[0].fd_name = -1;
1933	fr->fr_tifs[1].fd_name = -1;
1934	fr->fr_group = -1;
1935	fr->fr_grhead = -1;
1936	fr->fr_icmphead = -1;
1937	if (size == 0) {
1938		fr->fr_size = sizeof(*fr) + LIFNAMSIZ * 7 + FR_GROUPLEN * 2;
1939		fr->fr_size += sizeof(fripf_t) + 16;
1940		fr->fr_size += 9;	/* room for \0's */
1941	} else {
1942		char *names = fr->fr_names;
1943		int nlen = fr->fr_namelen;
1944
1945		fr->fr_size = size;
1946		if (old->fr_ifnames[0][0] != '\0') {
1947			fr->fr_ifnames[0] = nlen;
1948			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[0],
1949					    LIFNAMSIZ);
1950		}
1951		if (old->fr_ifnames[1][0] != '\0') {
1952			fr->fr_ifnames[1] = nlen;
1953			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[1],
1954					    LIFNAMSIZ);
1955		}
1956		if (old->fr_ifnames[2][0] != '\0') {
1957			fr->fr_ifnames[2] = nlen;
1958			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[2],
1959					    LIFNAMSIZ);
1960		}
1961		if (old->fr_ifnames[3][0] != '\0') {
1962			fr->fr_ifnames[3] = nlen;
1963			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[3],
1964					    LIFNAMSIZ);
1965		}
1966		if (old->fr_tifs[0].fd_ifname[0] != '\0') {
1967			fr->fr_tifs[0].fd_name = nlen;
1968			nlen = ipf_addfrstr(names, nlen,
1969					    old->fr_tifs[0].fd_ifname,
1970					    LIFNAMSIZ);
1971		}
1972		if (old->fr_tifs[1].fd_ifname[0] != '\0') {
1973			fr->fr_tifs[1].fd_name = nlen;
1974			nlen = ipf_addfrstr(names, nlen,
1975					    old->fr_tifs[1].fd_ifname,
1976					    LIFNAMSIZ);
1977		}
1978		if (old->fr_dif.fd_ifname[0] != '\0') {
1979			fr->fr_dif.fd_name = nlen;
1980			nlen = ipf_addfrstr(names, nlen,
1981					    old->fr_dif.fd_ifname, LIFNAMSIZ);
1982		}
1983		if (old->fr_group[0] != '\0') {
1984			fr->fr_group = nlen;
1985			nlen = ipf_addfrstr(names, nlen,
1986					    old->fr_group, LIFNAMSIZ);
1987		}
1988		if (old->fr_grhead[0] != '\0') {
1989			fr->fr_grhead = nlen;
1990			nlen = ipf_addfrstr(names, nlen,
1991					    old->fr_grhead, LIFNAMSIZ);
1992		}
1993		fr->fr_namelen = nlen;
1994
1995		if (old->fr_type == FR_T_IPF) {
1996			int offset = fr->fr_namelen;
1997			ipfobj_t obj;
1998			int error;
1999
2000			obj.ipfo_type = IPFOBJ_FRIPF;
2001			obj.ipfo_rev = 4010100;
2002			obj.ipfo_ptr = old->fr_data;
2003
2004			if ((offset & 7) != 0)
2005				offset += 8 - (offset & 7);
2006			error = ipf_in_compat(softc, &obj,
2007					      fr->fr_names + offset, 0);
2008			if (error == 0) {
2009				fr->fr_data = fr->fr_names + offset;
2010				fr->fr_dsize = sizeof(fripf_t);
2011			}
2012		}
2013	}
2014}
2015
2016static void
2017frentry_4_1_16_to_current(softc, old, current, size)
2018	ipf_main_softc_t *softc;
2019	frentry_4_1_16_t *old;
2020	void *current;
2021	int size;
2022{
2023	frentry_t *fr = (frentry_t *)current;
2024
2025	fr->fr_comment = -1;
2026	fr->fr_ref = old->fr_ref;
2027	fr->fr_statecnt = old->fr_statecnt;
2028	fr->fr_hits = old->fr_hits;
2029	fr->fr_bytes = old->fr_bytes;
2030	fr->fr_lastpkt.tv_sec = old->fr_lastpkt.tv_sec;
2031	fr->fr_lastpkt.tv_usec = old->fr_lastpkt.tv_usec;
2032	bcopy(&old->fr_dun, &fr->fr_dun, sizeof(old->fr_dun));
2033	fr->fr_func = old->fr_func;
2034	fr->fr_dsize = old->fr_dsize;
2035	fr->fr_pps = old->fr_pps;
2036	fr->fr_statemax = old->fr_statemax;
2037	fr->fr_flineno = old->fr_flineno;
2038	fr->fr_type = old->fr_type;
2039	fr->fr_flags = fr_frflags4to5(old->fr_flags);
2040	fr->fr_logtag = old->fr_logtag;
2041	fr->fr_collect = old->fr_collect;
2042	fr->fr_arg = old->fr_arg;
2043	fr->fr_loglevel = old->fr_loglevel;
2044	fr->fr_age[0] = old->fr_age[0];
2045	fr->fr_age[1] = old->fr_age[1];
2046	fr->fr_tifs[0].fd_ip6 = old->fr_tifs[0].ofd_ip6;
2047	fr->fr_tifs[0].fd_type = FRD_NORMAL;
2048	fr->fr_tifs[1].fd_ip6 = old->fr_tifs[1].ofd_ip6;
2049	fr->fr_tifs[1].fd_type = FRD_NORMAL;
2050	fr->fr_dif.fd_ip6 = old->fr_dif.ofd_ip6;
2051	fr->fr_dif.fd_type = FRD_NORMAL;
2052	if (old->fr_v == 4)
2053		fr->fr_family = AF_INET;
2054	if (old->fr_v == 6)
2055		fr->fr_family = AF_INET6;
2056	fr->fr_icode = old->fr_icode;
2057	fr->fr_cksum = old->fr_cksum;
2058	fr->fr_namelen = 0;
2059	fr->fr_ifnames[0] = -1;
2060	fr->fr_ifnames[1] = -1;
2061	fr->fr_ifnames[2] = -1;
2062	fr->fr_ifnames[3] = -1;
2063	fr->fr_dif.fd_name = -1;
2064	fr->fr_tifs[0].fd_name = -1;
2065	fr->fr_tifs[1].fd_name = -1;
2066	fr->fr_group = -1;
2067	fr->fr_grhead = -1;
2068	fr->fr_icmphead = -1;
2069	if (size == 0) {
2070		fr->fr_size = sizeof(*fr) + LIFNAMSIZ * 7 + FR_GROUPLEN * 2;
2071		fr->fr_size += 9;	/* room for \0's */
2072	} else {
2073		char *names = fr->fr_names;
2074		int nlen = fr->fr_namelen;
2075
2076		fr->fr_size = size;
2077		if (old->fr_ifnames[0][0] != '\0') {
2078			fr->fr_ifnames[0] = nlen;
2079			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[0],
2080					    LIFNAMSIZ);
2081		}
2082		if (old->fr_ifnames[1][0] != '\0') {
2083			fr->fr_ifnames[1] = nlen;
2084			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[1],
2085					    LIFNAMSIZ);
2086		}
2087		if (old->fr_ifnames[2][0] != '\0') {
2088			fr->fr_ifnames[2] = nlen;
2089			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[2],
2090					    LIFNAMSIZ);
2091		}
2092		if (old->fr_ifnames[3][0] != '\0') {
2093			fr->fr_ifnames[3] = nlen;
2094			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[3],
2095					    LIFNAMSIZ);
2096		}
2097		if (old->fr_tifs[0].fd_ifname[0] != '\0') {
2098			fr->fr_tifs[0].fd_name = nlen;
2099			nlen = ipf_addfrstr(names, nlen,
2100					    old->fr_tifs[0].fd_ifname,
2101					    LIFNAMSIZ);
2102		}
2103		if (old->fr_tifs[1].fd_ifname[0] != '\0') {
2104			fr->fr_tifs[1].fd_name = nlen;
2105			nlen = ipf_addfrstr(names, nlen,
2106					    old->fr_tifs[1].fd_ifname,
2107					    LIFNAMSIZ);
2108		}
2109		if (old->fr_dif.fd_ifname[0] != '\0') {
2110			fr->fr_dif.fd_name = nlen;
2111			nlen = ipf_addfrstr(names, nlen,
2112					    old->fr_dif.fd_ifname, LIFNAMSIZ);
2113		}
2114		if (old->fr_group[0] != '\0') {
2115			fr->fr_group = nlen;
2116			nlen = ipf_addfrstr(names, nlen,
2117					    old->fr_group, LIFNAMSIZ);
2118		}
2119		if (old->fr_grhead[0] != '\0') {
2120			fr->fr_grhead = nlen;
2121			nlen = ipf_addfrstr(names, nlen,
2122					    old->fr_grhead, LIFNAMSIZ);
2123		}
2124		fr->fr_namelen = nlen;
2125
2126		if (old->fr_type == FR_T_IPF) {
2127			int offset = fr->fr_namelen;
2128			ipfobj_t obj;
2129			int error;
2130
2131			obj.ipfo_type = IPFOBJ_FRIPF;
2132			obj.ipfo_rev = 4010100;
2133			obj.ipfo_ptr = old->fr_data;
2134
2135			if ((offset & 7) != 0)
2136				offset += 8 - (offset & 7);
2137			error = ipf_in_compat(softc, &obj,
2138					      fr->fr_names + offset, 0);
2139			if (error == 0) {
2140				fr->fr_data = fr->fr_names + offset;
2141				fr->fr_dsize = sizeof(fripf_t);
2142			}
2143		}
2144	}
2145}
2146
2147
2148static void
2149frentry_4_1_0_to_current(softc, old, current, size)
2150	ipf_main_softc_t *softc;
2151	frentry_4_1_0_t *old;
2152	void *current;
2153	int size;
2154{
2155	frentry_t *fr = (frentry_t *)current;
2156
2157	fr->fr_size = sizeof(*fr);
2158	fr->fr_comment = -1;
2159	fr->fr_ref = old->fr_ref;
2160	fr->fr_statecnt = old->fr_statecnt;
2161	fr->fr_hits = old->fr_hits;
2162	fr->fr_bytes = old->fr_bytes;
2163	fr->fr_lastpkt.tv_sec = old->fr_lastpkt.tv_sec;
2164	fr->fr_lastpkt.tv_usec = old->fr_lastpkt.tv_usec;
2165	bcopy(&old->fr_dun, &fr->fr_dun, sizeof(old->fr_dun));
2166	fr->fr_func = old->fr_func;
2167	fr->fr_dsize = old->fr_dsize;
2168	fr->fr_pps = old->fr_pps;
2169	fr->fr_statemax = old->fr_statemax;
2170	fr->fr_flineno = old->fr_flineno;
2171	fr->fr_type = old->fr_type;
2172	fr->fr_flags = fr_frflags4to5(old->fr_flags);
2173	fr->fr_logtag = old->fr_logtag;
2174	fr->fr_collect = old->fr_collect;
2175	fr->fr_arg = old->fr_arg;
2176	fr->fr_loglevel = old->fr_loglevel;
2177	fr->fr_age[0] = old->fr_age[0];
2178	fr->fr_age[1] = old->fr_age[1];
2179	fr->fr_tifs[0].fd_ip6 = old->fr_tifs[0].ofd_ip6;
2180	fr->fr_tifs[0].fd_type = FRD_NORMAL;
2181	fr->fr_tifs[1].fd_ip6 = old->fr_tifs[1].ofd_ip6;
2182	fr->fr_tifs[1].fd_type = FRD_NORMAL;
2183	fr->fr_dif.fd_ip6 = old->fr_dif.ofd_ip6;
2184	fr->fr_dif.fd_type = FRD_NORMAL;
2185	if (old->fr_v == 4)
2186		fr->fr_family = AF_INET;
2187	if (old->fr_v == 6)
2188		fr->fr_family = AF_INET6;
2189	fr->fr_icode = old->fr_icode;
2190	fr->fr_cksum = old->fr_cksum;
2191	fr->fr_namelen = 0;
2192	fr->fr_ifnames[0] = -1;
2193	fr->fr_ifnames[1] = -1;
2194	fr->fr_ifnames[2] = -1;
2195	fr->fr_ifnames[3] = -1;
2196	fr->fr_dif.fd_name = -1;
2197	fr->fr_tifs[0].fd_name = -1;
2198	fr->fr_tifs[1].fd_name = -1;
2199	fr->fr_group = -1;
2200	fr->fr_grhead = -1;
2201	fr->fr_icmphead = -1;
2202	if (size == 0) {
2203		fr->fr_size = sizeof(*fr) + LIFNAMSIZ * 7 + FR_GROUPLEN * 2;
2204		fr->fr_size += 9;	/* room for \0's */
2205	} else {
2206		char *names = fr->fr_names;
2207		int nlen = fr->fr_namelen;
2208
2209		fr->fr_size = size;
2210		if (old->fr_ifnames[0][0] != '\0') {
2211			fr->fr_ifnames[0] = nlen;
2212			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[0],
2213					    LIFNAMSIZ);
2214		}
2215		if (old->fr_ifnames[1][0] != '\0') {
2216			fr->fr_ifnames[1] = nlen;
2217			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[1],
2218					    LIFNAMSIZ);
2219		}
2220		if (old->fr_ifnames[2][0] != '\0') {
2221			fr->fr_ifnames[2] = nlen;
2222			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[2],
2223					    LIFNAMSIZ);
2224		}
2225		if (old->fr_ifnames[3][0] != '\0') {
2226			fr->fr_ifnames[3] = nlen;
2227			nlen = ipf_addfrstr(names, nlen, old->fr_ifnames[3],
2228					    LIFNAMSIZ);
2229		}
2230		if (old->fr_tifs[0].fd_ifname[0] != '\0') {
2231			fr->fr_tifs[0].fd_name = nlen;
2232			nlen = ipf_addfrstr(names, nlen,
2233					    old->fr_tifs[0].fd_ifname,
2234					    LIFNAMSIZ);
2235		}
2236		if (old->fr_tifs[1].fd_ifname[0] != '\0') {
2237			fr->fr_tifs[1].fd_name = nlen;
2238			nlen = ipf_addfrstr(names, nlen,
2239					    old->fr_tifs[1].fd_ifname,
2240					    LIFNAMSIZ);
2241		}
2242		if (old->fr_dif.fd_ifname[0] != '\0') {
2243			fr->fr_dif.fd_name = nlen;
2244			nlen = ipf_addfrstr(names, nlen,
2245					    old->fr_dif.fd_ifname, LIFNAMSIZ);
2246		}
2247		if (old->fr_group[0] != '\0') {
2248			fr->fr_group = nlen;
2249			nlen = ipf_addfrstr(names, nlen,
2250					    old->fr_group, LIFNAMSIZ);
2251		}
2252		if (old->fr_grhead[0] != '\0') {
2253			fr->fr_grhead = nlen;
2254			nlen = ipf_addfrstr(names, nlen,
2255					    old->fr_grhead, LIFNAMSIZ);
2256		}
2257		fr->fr_namelen = nlen;
2258
2259		if (old->fr_type == FR_T_IPF) {
2260			int offset = fr->fr_namelen;
2261			ipfobj_t obj;
2262			int error;
2263
2264			obj.ipfo_type = IPFOBJ_FRIPF;
2265			obj.ipfo_rev = 4010100;
2266			obj.ipfo_ptr = old->fr_data;
2267
2268			if ((offset & 7) != 0)
2269				offset += 8 - (offset & 7);
2270				offset += 8 - (offset & 7);
2271			error = ipf_in_compat(softc, &obj,
2272					      fr->fr_names + offset, 0);
2273			if (error == 0) {
2274				fr->fr_data = fr->fr_names + offset;
2275				fr->fr_dsize = sizeof(fripf_t);
2276			}
2277		}
2278	}
2279}
2280
2281
2282static void
2283friostat_4_1_33_to_current(old, current)
2284	friostat_4_1_33_t *old;
2285	void *current;
2286{
2287	friostat_t *fiop = (friostat_t *)current;
2288
2289	bcopy(&old->of_st[0], &fiop->f_st[0].fr_pass, sizeof(old->of_st[0]));
2290	bcopy(&old->of_st[1], &fiop->f_st[1].fr_pass, sizeof(old->of_st[1]));
2291
2292	fiop->f_ipf[0][0] = old->f_ipf[0][0];
2293	fiop->f_ipf[0][1] = old->f_ipf[0][1];
2294	fiop->f_ipf[1][0] = old->f_ipf[1][0];
2295	fiop->f_ipf[1][1] = old->f_ipf[1][1];
2296	fiop->f_acct[0][0] = old->f_acct[0][0];
2297	fiop->f_acct[0][1] = old->f_acct[0][1];
2298	fiop->f_acct[1][0] = old->f_acct[1][0];
2299	fiop->f_acct[1][1] = old->f_acct[1][1];
2300	fiop->f_auth = fiop->f_auth;
2301	bcopy(&old->f_groups, &fiop->f_groups, sizeof(old->f_groups));
2302	bcopy(&old->f_froute, &fiop->f_froute, sizeof(old->f_froute));
2303	fiop->f_ticks = old->f_ticks;
2304	bcopy(&old->f_locks, &fiop->f_locks, sizeof(old->f_locks));
2305	fiop->f_defpass = old->f_defpass;
2306	fiop->f_active = old->f_active;
2307	fiop->f_running = old->f_running;
2308	fiop->f_logging = old->f_logging;
2309	fiop->f_features = old->f_features;
2310	bcopy(old->f_version, fiop->f_version, sizeof(old->f_version));
2311}
2312
2313
2314static void
2315friostat_4_1_0_to_current(old, current)
2316	friostat_4_1_0_t *old;
2317	void *current;
2318{
2319	friostat_t *fiop = (friostat_t *)current;
2320
2321	bcopy(&old->of_st[0], &fiop->f_st[0].fr_pass, sizeof(old->of_st[0]));
2322	bcopy(&old->of_st[1], &fiop->f_st[1].fr_pass, sizeof(old->of_st[1]));
2323
2324	fiop->f_ipf[0][0] = old->f_ipf[0][0];
2325	fiop->f_ipf[0][1] = old->f_ipf[0][1];
2326	fiop->f_ipf[1][0] = old->f_ipf[1][0];
2327	fiop->f_ipf[1][1] = old->f_ipf[1][1];
2328	fiop->f_acct[0][0] = old->f_acct[0][0];
2329	fiop->f_acct[0][1] = old->f_acct[0][1];
2330	fiop->f_acct[1][0] = old->f_acct[1][0];
2331	fiop->f_acct[1][1] = old->f_acct[1][1];
2332	fiop->f_auth = fiop->f_auth;
2333	bcopy(&old->f_groups, &fiop->f_groups, sizeof(old->f_groups));
2334	bcopy(&old->f_froute, &fiop->f_froute, sizeof(old->f_froute));
2335	fiop->f_ticks = old->f_ticks;
2336	bcopy(&old->f_locks, &fiop->f_locks, sizeof(old->f_locks));
2337	fiop->f_defpass = old->f_defpass;
2338	fiop->f_active = old->f_active;
2339	fiop->f_running = old->f_running;
2340	fiop->f_logging = old->f_logging;
2341	fiop->f_features = old->f_features;
2342	bcopy(old->f_version, fiop->f_version, sizeof(old->f_version));
2343}
2344
2345
2346static void
2347ipnat_4_1_14_to_current(old, current, size)
2348	ipnat_4_1_14_t *old;
2349	void *current;
2350	int size;
2351{
2352	ipnat_t *np = (ipnat_t *)current;
2353
2354	np->in_space = old->in_space;
2355	np->in_hv[0] = old->in_hv;
2356	np->in_hv[1] = old->in_hv;
2357	np->in_flineno = old->in_flineno;
2358	if (old->in_redir == NAT_REDIRECT)
2359		np->in_dpnext = old->in_pnext;
2360	else
2361		np->in_spnext = old->in_pnext;
2362	np->in_v[0] = old->in_v;
2363	np->in_v[1] = old->in_v;
2364	np->in_flags = old->in_flags;
2365	np->in_mssclamp = old->in_mssclamp;
2366	np->in_age[0] = old->in_age[0];
2367	np->in_age[1] = old->in_age[1];
2368	np->in_redir = old->in_redir;
2369	np->in_pr[0] = old->in_p;
2370	np->in_pr[1] = old->in_p;
2371	if (np->in_redir == NAT_REDIRECT) {
2372		np->in_ndst.na_nextaddr = old->in_next6;
2373		np->in_ndst.na_addr[0] = old->in_in[0];
2374		np->in_ndst.na_addr[1] = old->in_in[1];
2375		np->in_ndst.na_atype = FRI_NORMAL;
2376		np->in_odst.na_addr[0] = old->in_out[0];
2377		np->in_odst.na_addr[1] = old->in_out[1];
2378		np->in_odst.na_atype = FRI_NORMAL;
2379		np->in_osrc.na_addr[0] = old->in_src[0];
2380		np->in_osrc.na_addr[1] = old->in_src[1];
2381		np->in_osrc.na_atype = FRI_NORMAL;
2382	} else {
2383		np->in_nsrc.na_nextaddr = old->in_next6;
2384		np->in_nsrc.na_addr[0] = old->in_out[0];
2385		np->in_nsrc.na_addr[1] = old->in_out[1];
2386		np->in_nsrc.na_atype = FRI_NORMAL;
2387		np->in_osrc.na_addr[0] = old->in_in[0];
2388		np->in_osrc.na_addr[1] = old->in_in[1];
2389		np->in_osrc.na_atype = FRI_NORMAL;
2390		np->in_odst.na_addr[0] = old->in_src[0];
2391		np->in_odst.na_addr[1] = old->in_src[1];
2392		np->in_odst.na_atype = FRI_NORMAL;
2393	}
2394	ipfv4tuctov5(&old->in_tuc, &np->in_tuc);
2395	if (np->in_redir == NAT_REDIRECT) {
2396		np->in_dpmin = old->in_port[0];
2397		np->in_dpmax = old->in_port[1];
2398	} else {
2399		np->in_spmin = old->in_port[0];
2400		np->in_spmax = old->in_port[1];
2401	}
2402	np->in_ppip = old->in_ppip;
2403	np->in_ippip = old->in_ippip;
2404	np->in_tag = old->in_tag;
2405
2406	np->in_namelen = 0;
2407	np->in_plabel = -1;
2408	np->in_ifnames[0] = -1;
2409	np->in_ifnames[1] = -1;
2410
2411	if (size == 0) {
2412		np->in_size = sizeof(*np);
2413		np->in_size += LIFNAMSIZ * 2 + APR_LABELLEN;
2414		np->in_size += 3;
2415	} else {
2416		int nlen = np->in_namelen;
2417		char *names = np->in_names;
2418
2419		if (old->in_ifnames[0][0] != '\0') {
2420			np->in_ifnames[0] = nlen;
2421			nlen = ipf_addfrstr(names, nlen, old->in_ifnames[0],
2422					    LIFNAMSIZ);
2423		}
2424		if (old->in_ifnames[1][0] != '\0') {
2425			np->in_ifnames[0] = nlen;
2426			nlen = ipf_addfrstr(names, nlen, old->in_ifnames[1],
2427					    LIFNAMSIZ);
2428		}
2429		if (old->in_plabel[0] != '\0') {
2430			np->in_plabel = nlen;
2431			nlen = ipf_addfrstr(names, nlen, old->in_plabel,
2432					    LIFNAMSIZ);
2433		}
2434		np->in_namelen = nlen;
2435		np->in_size = size;
2436	}
2437}
2438
2439
2440static void
2441ipnat_4_1_0_to_current(old, current, size)
2442	ipnat_4_1_0_t *old;
2443	void *current;
2444	int size;
2445{
2446	ipnat_t *np = (ipnat_t *)current;
2447
2448	np->in_space = old->in_space;
2449	np->in_hv[0] = old->in_hv;
2450	np->in_hv[1] = old->in_hv;
2451	np->in_flineno = old->in_flineno;
2452	if (old->in_redir == NAT_REDIRECT)
2453		np->in_dpnext = old->in_pnext;
2454	else
2455		np->in_spnext = old->in_pnext;
2456	np->in_v[0] = old->in_v;
2457	np->in_v[1] = old->in_v;
2458	np->in_flags = old->in_flags;
2459	np->in_mssclamp = old->in_mssclamp;
2460	np->in_age[0] = old->in_age[0];
2461	np->in_age[1] = old->in_age[1];
2462	np->in_redir = old->in_redir;
2463	np->in_pr[0] = old->in_p;
2464	np->in_pr[1] = old->in_p;
2465	if (np->in_redir == NAT_REDIRECT) {
2466		np->in_ndst.na_nextaddr = old->in_next6;
2467		bcopy(&old->in_in, &np->in_ndst.na_addr, sizeof(old->in_in));
2468		bcopy(&old->in_out, &np->in_odst.na_addr, sizeof(old->in_out));
2469		bcopy(&old->in_src, &np->in_osrc.na_addr, sizeof(old->in_src));
2470	} else {
2471		np->in_nsrc.na_nextaddr = old->in_next6;
2472		bcopy(&old->in_in, &np->in_osrc.na_addr, sizeof(old->in_in));
2473		bcopy(&old->in_out, &np->in_nsrc.na_addr, sizeof(old->in_out));
2474		bcopy(&old->in_src, &np->in_odst.na_addr, sizeof(old->in_src));
2475	}
2476	ipfv4tuctov5(&old->in_tuc, &np->in_tuc);
2477	if (np->in_redir == NAT_REDIRECT) {
2478		np->in_dpmin = old->in_port[0];
2479		np->in_dpmax = old->in_port[1];
2480	} else {
2481		np->in_spmin = old->in_port[0];
2482		np->in_spmax = old->in_port[1];
2483	}
2484	np->in_ppip = old->in_ppip;
2485	np->in_ippip = old->in_ippip;
2486	bcopy(&old->in_tag, &np->in_tag, sizeof(np->in_tag));
2487
2488	np->in_namelen = 0;
2489	np->in_plabel = -1;
2490	np->in_ifnames[0] = -1;
2491	np->in_ifnames[1] = -1;
2492
2493	if (size == 0) {
2494		np->in_size = sizeof(*np);
2495		np->in_size += LIFNAMSIZ * 2 + APR_LABELLEN;
2496		np->in_size += 3;
2497	} else {
2498		int nlen = np->in_namelen;
2499		char *names = np->in_names;
2500
2501		if (old->in_ifnames[0][0] != '\0') {
2502			np->in_ifnames[0] = nlen;
2503			nlen = ipf_addfrstr(names, nlen, old->in_ifnames[0],
2504					    LIFNAMSIZ);
2505		}
2506		if (old->in_ifnames[1][0] != '\0') {
2507			np->in_ifnames[0] = nlen;
2508			nlen = ipf_addfrstr(names, nlen, old->in_ifnames[1],
2509					    LIFNAMSIZ);
2510		}
2511		if (old->in_plabel[0] != '\0') {
2512			np->in_plabel = nlen;
2513			nlen = ipf_addfrstr(names, nlen, old->in_plabel,
2514					    LIFNAMSIZ);
2515		}
2516		np->in_namelen = nlen;
2517		np->in_size = size;
2518	}
2519}
2520
2521
2522static void
2523frauth_4_1_32_to_current(old, current)
2524	frauth_4_1_32_t *old;
2525	void *current;
2526{
2527	frauth_t *fra = (frauth_t *)current;
2528
2529	fra->fra_age = old->fra_age;
2530	fra->fra_len = old->fra_len;
2531	fra->fra_index = old->fra_index;
2532	fra->fra_pass = old->fra_pass;
2533	fr_info_4_1_32_to_current(&old->fra_info, &fra->fra_info);
2534	fra->fra_buf = old->fra_buf;
2535	fra->fra_flx = old->fra_flx;
2536#if SOLARIS
2537	fra->fra_q = old->fra_q;
2538	fra->fra_m = old->fra_m;
2539#endif
2540}
2541
2542
2543static void
2544frauth_4_1_29_to_current(old, current)
2545	frauth_4_1_29_t *old;
2546	void *current;
2547{
2548	frauth_t *fra = (frauth_t *)current;
2549
2550	fra->fra_age = old->fra_age;
2551	fra->fra_len = old->fra_len;
2552	fra->fra_index = old->fra_index;
2553	fra->fra_pass = old->fra_pass;
2554	fr_info_4_1_24_to_current(&old->fra_info, &fra->fra_info);
2555	fra->fra_buf = old->fra_buf;
2556	fra->fra_flx = old->fra_flx;
2557#if SOLARIS
2558	fra->fra_q = old->fra_q;
2559	fra->fra_m = old->fra_m;
2560#endif
2561}
2562
2563
2564static void
2565frauth_4_1_24_to_current(old, current)
2566	frauth_4_1_24_t *old;
2567	void *current;
2568{
2569	frauth_t *fra = (frauth_t *)current;
2570
2571	fra->fra_age = old->fra_age;
2572	fra->fra_len = old->fra_len;
2573	fra->fra_index = old->fra_index;
2574	fra->fra_pass = old->fra_pass;
2575	fr_info_4_1_24_to_current(&old->fra_info, &fra->fra_info);
2576	fra->fra_buf = old->fra_buf;
2577#if SOLARIS
2578	fra->fra_q = old->fra_q;
2579	fra->fra_m = old->fra_m;
2580#endif
2581}
2582
2583
2584static void
2585frauth_4_1_23_to_current(old, current)
2586	frauth_4_1_23_t *old;
2587	void *current;
2588{
2589	frauth_t *fra = (frauth_t *)current;
2590
2591	fra->fra_age = old->fra_age;
2592	fra->fra_len = old->fra_len;
2593	fra->fra_index = old->fra_index;
2594	fra->fra_pass = old->fra_pass;
2595	fr_info_4_1_23_to_current(&old->fra_info, &fra->fra_info);
2596	fra->fra_buf = old->fra_buf;
2597#if SOLARIS
2598	fra->fra_q = old->fra_q;
2599	fra->fra_m = old->fra_m;
2600#endif
2601}
2602
2603
2604static void
2605frauth_4_1_11_to_current(old, current)
2606	frauth_4_1_11_t *old;
2607	void *current;
2608{
2609	frauth_t *fra = (frauth_t *)current;
2610
2611	fra->fra_age = old->fra_age;
2612	fra->fra_len = old->fra_len;
2613	fra->fra_index = old->fra_index;
2614	fra->fra_pass = old->fra_pass;
2615	fr_info_4_1_11_to_current(&old->fra_info, &fra->fra_info);
2616	fra->fra_buf = old->fra_buf;
2617#if SOLARIS
2618	fra->fra_q = old->fra_q;
2619	fra->fra_m = old->fra_m;
2620#endif
2621}
2622
2623
2624static void
2625fr_info_4_1_32_to_current(old, current)
2626	fr_info_4_1_32_t *old;
2627	void *current;
2628{
2629	fr_info_t *fin = (fr_info_t *)current;
2630
2631	fin->fin_ifp = old->fin_ifp;
2632	ipf_v4iptov5(&old->fin_fi, &fin->fin_fi);
2633	bcopy(&old->fin_dat, &fin->fin_dat, sizeof(old->fin_dat));
2634	fin->fin_out = old->fin_out;
2635	fin->fin_rev = old->fin_rev;
2636	fin->fin_hlen = old->fin_hlen;
2637	fin->fin_tcpf = old->ofin_tcpf;
2638	fin->fin_icode = old->fin_icode;
2639	fin->fin_rule = old->fin_rule;
2640	bcopy(old->fin_group, fin->fin_group, sizeof(old->fin_group));
2641	fin->fin_fr = old->fin_fr;
2642	fin->fin_dp = old->fin_dp;
2643	fin->fin_dlen = old->fin_dlen;
2644	fin->fin_plen = old->fin_plen;
2645	fin->fin_ipoff = old->fin_ipoff;
2646	fin->fin_id = old->fin_id;
2647	fin->fin_off = old->fin_off;
2648	fin->fin_depth = old->fin_depth;
2649	fin->fin_error = old->fin_error;
2650	fin->fin_cksum = old->fin_cksum;
2651	fin->fin_nattag = old->fin_nattag;
2652	fin->fin_ip = old->ofin_ip;
2653	fin->fin_mp = old->fin_mp;
2654	fin->fin_m = old->fin_m;
2655#if SOLARIS
2656	fin->fin_qfm = old->fin_qfm;
2657	fin->fin_qpi = old->fin_qpi;
2658#endif
2659}
2660
2661
2662static void
2663fr_info_4_1_24_to_current(old, current)
2664	fr_info_4_1_24_t *old;
2665	void *current;
2666{
2667	fr_info_t *fin = (fr_info_t *)current;
2668
2669	fin->fin_ifp = old->fin_ifp;
2670	ipf_v4iptov5(&old->fin_fi, &fin->fin_fi);
2671	bcopy(&old->fin_dat, &fin->fin_dat, sizeof(old->fin_dat));
2672	fin->fin_out = old->fin_out;
2673	fin->fin_rev = old->fin_rev;
2674	fin->fin_hlen = old->fin_hlen;
2675	fin->fin_tcpf = old->ofin_tcpf;
2676	fin->fin_icode = old->fin_icode;
2677	fin->fin_rule = old->fin_rule;
2678	bcopy(old->fin_group, fin->fin_group, sizeof(old->fin_group));
2679	fin->fin_fr = old->fin_fr;
2680	fin->fin_dp = old->fin_dp;
2681	fin->fin_dlen = old->fin_dlen;
2682	fin->fin_plen = old->fin_plen;
2683	fin->fin_ipoff = old->fin_ipoff;
2684	fin->fin_id = old->fin_id;
2685	fin->fin_off = old->fin_off;
2686	fin->fin_depth = old->fin_depth;
2687	fin->fin_error = old->fin_error;
2688	fin->fin_cksum = old->fin_cksum;
2689	fin->fin_nattag = old->fin_nattag;
2690	fin->fin_ip = old->ofin_ip;
2691	fin->fin_mp = old->fin_mp;
2692	fin->fin_m = old->fin_m;
2693#if SOLARIS
2694	fin->fin_qfm = old->fin_qfm;
2695	fin->fin_qpi = old->fin_qpi;
2696#endif
2697}
2698
2699
2700static void
2701fr_info_4_1_23_to_current(old, current)
2702	fr_info_4_1_23_t *old;
2703	void *current;
2704{
2705	fr_info_t *fin = (fr_info_t *)current;
2706
2707	fin->fin_ifp = old->fin_ifp;
2708	ipf_v4iptov5(&old->fin_fi, &fin->fin_fi);
2709	bcopy(&old->fin_dat, &fin->fin_dat, sizeof(old->fin_dat));
2710	fin->fin_out = old->fin_out;
2711	fin->fin_rev = old->fin_rev;
2712	fin->fin_hlen = old->fin_hlen;
2713	fin->fin_tcpf = old->ofin_tcpf;
2714	fin->fin_icode = old->fin_icode;
2715	fin->fin_rule = old->fin_rule;
2716	bcopy(old->fin_group, fin->fin_group, sizeof(old->fin_group));
2717	fin->fin_fr = old->fin_fr;
2718	fin->fin_dp = old->fin_dp;
2719	fin->fin_dlen = old->fin_dlen;
2720	fin->fin_plen = old->fin_plen;
2721	fin->fin_ipoff = old->fin_ipoff;
2722	fin->fin_id = old->fin_id;
2723	fin->fin_off = old->fin_off;
2724	fin->fin_depth = old->fin_depth;
2725	fin->fin_error = old->fin_error;
2726	fin->fin_nattag = old->fin_nattag;
2727	fin->fin_ip = old->ofin_ip;
2728	fin->fin_mp = old->fin_mp;
2729	fin->fin_m = old->fin_m;
2730#if SOLARIS
2731	fin->fin_qfm = old->fin_qfm;
2732	fin->fin_qpi = old->fin_qpi;
2733#endif
2734}
2735
2736
2737static void
2738fr_info_4_1_11_to_current(old, current)
2739	fr_info_4_1_11_t *old;
2740	void *current;
2741{
2742	fr_info_t *fin = (fr_info_t *)current;
2743
2744	fin->fin_ifp = old->fin_ifp;
2745	ipf_v4iptov5(&old->fin_fi, &fin->fin_fi);
2746	bcopy(&old->fin_dat, &fin->fin_dat, sizeof(old->fin_dat));
2747	fin->fin_out = old->fin_out;
2748	fin->fin_rev = old->fin_rev;
2749	fin->fin_hlen = old->fin_hlen;
2750	fin->fin_tcpf = old->ofin_tcpf;
2751	fin->fin_icode = old->fin_icode;
2752	fin->fin_rule = old->fin_rule;
2753	bcopy(old->fin_group, fin->fin_group, sizeof(old->fin_group));
2754	fin->fin_fr = old->fin_fr;
2755	fin->fin_dp = old->fin_dp;
2756	fin->fin_dlen = old->fin_dlen;
2757	fin->fin_plen = old->fin_plen;
2758	fin->fin_ipoff = old->fin_ipoff;
2759	fin->fin_id = old->fin_id;
2760	fin->fin_off = old->fin_off;
2761	fin->fin_depth = old->fin_depth;
2762	fin->fin_error = old->fin_error;
2763	fin->fin_nattag = old->fin_nattag;
2764	fin->fin_ip = old->ofin_ip;
2765	fin->fin_mp = old->fin_mp;
2766	fin->fin_m = old->fin_m;
2767#if SOLARIS
2768	fin->fin_qfm = old->fin_qfm;
2769	fin->fin_qpi = old->fin_qpi;
2770#endif
2771}
2772
2773
2774static void
2775nat_4_1_3_to_current(nat_4_1_3_t *old, nat_t *current)
2776{
2777	bzero((void *)current, sizeof(*current));
2778	bcopy((void *)old, (void *)current, sizeof(*old));
2779}
2780
2781
2782static void
2783nat_4_1_14_to_current(nat_4_1_14_t *old, nat_t *current)
2784{
2785	bzero((void *)current, sizeof(*current));
2786	bcopy((void *)old, (void *)current, sizeof(*old));
2787}
2788
2789
2790static void
2791nat_save_4_1_16_to_current(softc, old, current)
2792	ipf_main_softc_t *softc;
2793	nat_save_4_1_16_t *old;
2794	void *current;
2795{
2796	nat_save_t *nats = (nat_save_t *)current;
2797
2798	nats->ipn_next = old->ipn_next;
2799	nat_4_1_14_to_current(&old->ipn_nat, &nats->ipn_nat);
2800	bcopy(&old->ipn_ipnat, &nats->ipn_ipnat, sizeof(old->ipn_ipnat));
2801	frentry_4_1_16_to_current(softc, &old->ipn_fr, &nats->ipn_fr, 0);
2802	nats->ipn_dsize = old->ipn_dsize;
2803	bcopy(old->ipn_data, nats->ipn_data, sizeof(nats->ipn_data));
2804}
2805
2806
2807static void
2808nat_save_4_1_14_to_current(softc, old, current)
2809	ipf_main_softc_t *softc;
2810	nat_save_4_1_14_t *old;
2811	void *current;
2812{
2813	nat_save_t *nats = (nat_save_t *)current;
2814
2815	nats->ipn_next = old->ipn_next;
2816	nat_4_1_14_to_current(&old->ipn_nat, &nats->ipn_nat);
2817	bcopy(&old->ipn_ipnat, &nats->ipn_ipnat, sizeof(old->ipn_ipnat));
2818	frentry_4_1_0_to_current(softc, &old->ipn_fr, &nats->ipn_fr, 0);
2819	nats->ipn_dsize = old->ipn_dsize;
2820	bcopy(old->ipn_data, nats->ipn_data, sizeof(nats->ipn_data));
2821}
2822
2823
2824static void
2825nat_save_4_1_3_to_current(softc, old, current)
2826	ipf_main_softc_t *softc;
2827	nat_save_4_1_3_t *old;
2828	void *current;
2829{
2830	nat_save_t *nats = (nat_save_t *)current;
2831
2832	nats->ipn_next = old->ipn_next;
2833	nat_4_1_3_to_current(&old->ipn_nat, &nats->ipn_nat);
2834	ipnat_4_1_0_to_current(&old->ipn_ipnat, &nats->ipn_ipnat, 0);
2835	frentry_4_1_0_to_current(softc, &old->ipn_fr, &nats->ipn_fr, 0);
2836	nats->ipn_dsize = old->ipn_dsize;
2837	bcopy(old->ipn_data, nats->ipn_data, sizeof(nats->ipn_data));
2838}
2839
2840
2841static void
2842natstat_current_to_4_1_32(current, old)
2843	void *current;
2844	natstat_4_1_32_t *old;
2845{
2846	natstat_t *ns = (natstat_t *)current;
2847
2848	old->ns_mapped[0] = ns->ns_side[0].ns_translated;
2849	old->ns_mapped[1] = ns->ns_side[1].ns_translated;
2850	old->ns_rules = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2851	old->ns_added = ns->ns_side[0].ns_added + ns->ns_side[1].ns_added;
2852	old->ns_expire = ns->ns_expire;
2853	old->ns_inuse = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2854	old->ns_logged = ns->ns_log_ok;
2855	old->ns_logfail = ns->ns_log_fail;
2856	old->ns_memfail = ns->ns_side[0].ns_memfail + ns->ns_side[1].ns_memfail;
2857	old->ns_badnat = ns->ns_side[0].ns_badnat + ns->ns_side[1].ns_badnat;
2858	old->ns_addtrpnt = ns->ns_addtrpnt;
2859	old->ns_table[0] = ns->ns_side[0].ns_table;
2860	old->ns_table[1] = ns->ns_side[1].ns_table;
2861	old->ns_maptable = NULL;
2862	old->ns_list = ns->ns_list;
2863	old->ns_apslist = NULL;
2864	old->ns_wilds = ns->ns_wilds;
2865	old->ns_nattab_sz = ns->ns_nattab_sz;
2866	old->ns_nattab_max = ns->ns_nattab_max;
2867	old->ns_rultab_sz = ns->ns_rultab_sz;
2868	old->ns_rdrtab_sz = ns->ns_rdrtab_sz;
2869	old->ns_trpntab_sz = ns->ns_trpntab_sz;
2870	old->ns_hostmap_sz = 0;
2871	old->ns_instances = ns->ns_instances;
2872	old->ns_maplist = ns->ns_maplist;
2873	old->ns_bucketlen[0] = (u_long *)ns->ns_side[0].ns_bucketlen;
2874	old->ns_bucketlen[1] = (u_long *)ns->ns_side[1].ns_bucketlen;
2875	old->ns_ticks = ns->ns_ticks;
2876	old->ns_orphans = ns->ns_orphans;
2877	old->ns_uncreate[0][0] = ns->ns_side[0].ns_uncreate[0];
2878	old->ns_uncreate[0][1] = ns->ns_side[0].ns_uncreate[1];
2879	old->ns_uncreate[1][0] = ns->ns_side[1].ns_uncreate[0];
2880	old->ns_uncreate[1][1] = ns->ns_side[1].ns_uncreate[1];
2881}
2882
2883
2884static void
2885natstat_current_to_4_1_27(current, old)
2886	void *current;
2887	natstat_4_1_27_t *old;
2888{
2889	natstat_t *ns = (natstat_t *)current;
2890
2891	old->ns_mapped[0] = ns->ns_side[0].ns_translated;
2892	old->ns_mapped[1] = ns->ns_side[1].ns_translated;
2893	old->ns_rules = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2894	old->ns_added = ns->ns_side[0].ns_added + ns->ns_side[1].ns_added;
2895	old->ns_expire = ns->ns_expire;
2896	old->ns_inuse = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2897	old->ns_logged = ns->ns_log_ok;
2898	old->ns_logfail = ns->ns_log_fail;
2899	old->ns_memfail = ns->ns_side[0].ns_memfail + ns->ns_side[1].ns_memfail;
2900	old->ns_badnat = ns->ns_side[0].ns_badnat + ns->ns_side[1].ns_badnat;
2901	old->ns_addtrpnt = ns->ns_addtrpnt;
2902	old->ns_table[0] = ns->ns_side[0].ns_table;
2903	old->ns_table[1] = ns->ns_side[1].ns_table;
2904	old->ns_maptable = NULL;
2905	old->ns_list = ns->ns_list;
2906	old->ns_apslist = NULL;
2907	old->ns_wilds = ns->ns_wilds;
2908	old->ns_nattab_sz = ns->ns_nattab_sz;
2909	old->ns_nattab_max = ns->ns_nattab_max;
2910	old->ns_rultab_sz = ns->ns_rultab_sz;
2911	old->ns_rdrtab_sz = ns->ns_rdrtab_sz;
2912	old->ns_trpntab_sz = ns->ns_trpntab_sz;
2913	old->ns_hostmap_sz = 0;
2914	old->ns_instances = ns->ns_instances;
2915	old->ns_maplist = ns->ns_maplist;
2916	old->ns_bucketlen[0] = (u_long *)ns->ns_side[0].ns_bucketlen;
2917	old->ns_bucketlen[1] = (u_long *)ns->ns_side[1].ns_bucketlen;
2918	old->ns_ticks = ns->ns_ticks;
2919	old->ns_orphans = ns->ns_orphans;
2920}
2921
2922
2923static void
2924natstat_current_to_4_1_16(current, old)
2925	void *current;
2926	natstat_4_1_16_t *old;
2927{
2928	natstat_t *ns = (natstat_t *)current;
2929
2930	old->ns_mapped[0] = ns->ns_side[0].ns_translated;
2931	old->ns_mapped[1] = ns->ns_side[1].ns_translated;
2932	old->ns_rules = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2933	old->ns_added = ns->ns_side[0].ns_added + ns->ns_side[1].ns_added;
2934	old->ns_expire = ns->ns_expire;
2935	old->ns_inuse = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2936	old->ns_logged = ns->ns_log_ok;
2937	old->ns_logfail = ns->ns_log_fail;
2938	old->ns_memfail = ns->ns_side[0].ns_memfail + ns->ns_side[1].ns_memfail;
2939	old->ns_badnat = ns->ns_side[0].ns_badnat + ns->ns_side[1].ns_badnat;
2940	old->ns_addtrpnt = ns->ns_addtrpnt;
2941	old->ns_table[0] = ns->ns_side[0].ns_table;
2942	old->ns_table[1] = ns->ns_side[1].ns_table;
2943	old->ns_maptable = NULL;
2944	old->ns_list = ns->ns_list;
2945	old->ns_apslist = NULL;
2946	old->ns_wilds = ns->ns_wilds;
2947	old->ns_nattab_sz = ns->ns_nattab_sz;
2948	old->ns_nattab_max = ns->ns_nattab_max;
2949	old->ns_rultab_sz = ns->ns_rultab_sz;
2950	old->ns_rdrtab_sz = ns->ns_rdrtab_sz;
2951	old->ns_trpntab_sz = ns->ns_trpntab_sz;
2952	old->ns_hostmap_sz = 0;
2953	old->ns_instances = ns->ns_instances;
2954	old->ns_maplist = ns->ns_maplist;
2955	old->ns_bucketlen[0] = (u_long *)ns->ns_side[0].ns_bucketlen;
2956	old->ns_bucketlen[1] = (u_long *)ns->ns_side[1].ns_bucketlen;
2957	old->ns_ticks = ns->ns_ticks;
2958}
2959
2960
2961static void
2962natstat_current_to_4_1_0(current, old)
2963	void *current;
2964	natstat_4_1_0_t *old;
2965{
2966	natstat_t *ns = (natstat_t *)current;
2967
2968	old->ns_mapped[0] = ns->ns_side[0].ns_translated;
2969	old->ns_mapped[1] = ns->ns_side[1].ns_translated;
2970	old->ns_rules = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2971	old->ns_added = ns->ns_side[0].ns_added + ns->ns_side[1].ns_added;
2972	old->ns_expire = ns->ns_expire;
2973	old->ns_inuse = ns->ns_side[0].ns_inuse + ns->ns_side[1].ns_inuse;
2974	old->ns_logged = ns->ns_log_ok;
2975	old->ns_logfail = ns->ns_log_fail;
2976	old->ns_memfail = ns->ns_side[0].ns_memfail + ns->ns_side[1].ns_memfail;
2977	old->ns_badnat = ns->ns_side[0].ns_badnat + ns->ns_side[1].ns_badnat;
2978	old->ns_addtrpnt = ns->ns_addtrpnt;
2979	old->ns_table[0] = ns->ns_side[0].ns_table;
2980	old->ns_table[1] = ns->ns_side[1].ns_table;
2981	old->ns_maptable = NULL;
2982	old->ns_list = ns->ns_list;
2983	old->ns_apslist = NULL;
2984	old->ns_wilds = ns->ns_wilds;
2985	old->ns_nattab_sz = ns->ns_nattab_sz;
2986	old->ns_nattab_max = ns->ns_nattab_max;
2987	old->ns_rultab_sz = ns->ns_rultab_sz;
2988	old->ns_rdrtab_sz = ns->ns_rdrtab_sz;
2989	old->ns_trpntab_sz = ns->ns_trpntab_sz;
2990	old->ns_hostmap_sz = 0;
2991	old->ns_instances = ns->ns_instances;
2992	old->ns_maplist = ns->ns_maplist;
2993	old->ns_bucketlen[0] = (u_long *)ns->ns_side[0].ns_bucketlen;
2994	old->ns_bucketlen[1] = (u_long *)ns->ns_side[1].ns_bucketlen;
2995}
2996
2997
2998static void
2999ipstate_save_current_to_4_1_16(current, old)
3000	void *current;
3001	ipstate_save_4_1_16_t *old;
3002{
3003	ipstate_save_t *ips = (ipstate_save_t *)current;
3004
3005	old->ips_next = ips->ips_next;
3006	ipstate_current_to_4_1_0(&ips->ips_is, &old->ips_is);
3007	frentry_current_to_4_1_16(&ips->ips_fr, &old->ips_fr);
3008}
3009
3010
3011static void
3012ipstate_save_current_to_4_1_0(current, old)
3013	void *current;
3014	ipstate_save_4_1_0_t *old;
3015{
3016	ipstate_save_t *ips = (ipstate_save_t *)current;
3017
3018	old->ips_next = ips->ips_next;
3019	ipstate_current_to_4_1_0(&ips->ips_is, &old->ips_is);
3020	frentry_current_to_4_1_0(&ips->ips_fr, &old->ips_fr);
3021}
3022
3023
3024int
3025ipf_out_compat(softc, obj, ptr)
3026	ipf_main_softc_t *softc;
3027	ipfobj_t *obj;
3028	void *ptr;
3029{
3030	frentry_t *fr;
3031	int error;
3032
3033	IPFERROR(140042);
3034	error = EINVAL;
3035
3036	switch (obj->ipfo_type)
3037	{
3038	default :
3039		break;
3040
3041	case IPFOBJ_FRENTRY :
3042		if (obj->ipfo_rev >= 4013400) {
3043			frentry_4_1_34_t *old;
3044
3045			KMALLOC(old, frentry_4_1_34_t *);
3046			if (old == NULL) {
3047				IPFERROR(140043);
3048				error = ENOMEM;
3049				break;
3050			}
3051			frentry_current_to_4_1_34(ptr, old);
3052			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3053			if (error == 0 && old->fr_dsize > 0) {
3054				char *dst = obj->ipfo_ptr;
3055
3056				fr = ptr;
3057				dst += sizeof(*old);
3058				error = COPYOUT(fr->fr_data, dst,
3059						old->fr_dsize);
3060				if (error != 0) {
3061					IPFERROR(140044);
3062				}
3063			}
3064			KFREE(old);
3065			obj->ipfo_size = sizeof(*old);
3066		} else if (obj->ipfo_rev >= 4011600) {
3067			frentry_4_1_16_t *old;
3068
3069			KMALLOC(old, frentry_4_1_16_t *);
3070			if (old == NULL) {
3071				IPFERROR(140045);
3072				error = ENOMEM;
3073				break;
3074			}
3075			frentry_current_to_4_1_16(ptr, old);
3076			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3077			if (error != 0) {
3078				IPFERROR(140046);
3079			}
3080			KFREE(old);
3081			obj->ipfo_size = sizeof(*old);
3082		} else {
3083			frentry_4_1_0_t *old;
3084
3085			KMALLOC(old, frentry_4_1_0_t *);
3086			if (old == NULL) {
3087				IPFERROR(140047);
3088				error = ENOMEM;
3089				break;
3090			}
3091			frentry_current_to_4_1_0(ptr, old);
3092			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3093			if (error != 0) {
3094				IPFERROR(140048);
3095			}
3096			KFREE(old);
3097			obj->ipfo_size = sizeof(*old);
3098		}
3099		break;
3100
3101	case IPFOBJ_IPFSTAT :
3102		if (obj->ipfo_rev >= 4013300) {
3103			friostat_4_1_33_t *old;
3104
3105			KMALLOC(old, friostat_4_1_33_t *);
3106			if (old == NULL) {
3107				IPFERROR(140049);
3108				error = ENOMEM;
3109				break;
3110			}
3111			friostat_current_to_4_1_33(ptr, old, obj->ipfo_rev);
3112			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3113			if (error != 0) {
3114				IPFERROR(140050);
3115			}
3116			KFREE(old);
3117		} else {
3118			friostat_4_1_0_t *old;
3119
3120			KMALLOC(old, friostat_4_1_0_t *);
3121			if (old == NULL) {
3122				IPFERROR(140051);
3123				error = ENOMEM;
3124				break;
3125			}
3126			friostat_current_to_4_1_0(ptr, old, obj->ipfo_rev);
3127			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3128			if (error != 0) {
3129				IPFERROR(140052);
3130			}
3131			KFREE(old);
3132		}
3133		break;
3134
3135	case IPFOBJ_IPFINFO :	/* unused */
3136		break;
3137
3138	case IPFOBJ_IPNAT :
3139		if (obj->ipfo_rev >= 4011400) {
3140			ipnat_4_1_14_t *old;
3141
3142			KMALLOC(old, ipnat_4_1_14_t *);
3143			if (old == NULL) {
3144				IPFERROR(140053);
3145				error = ENOMEM;
3146				break;
3147			}
3148			ipnat_current_to_4_1_14(ptr, old);
3149			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3150			if (error != 0) {
3151				IPFERROR(140054);
3152			}
3153			KFREE(old);
3154		} else {
3155			ipnat_4_1_0_t *old;
3156
3157			KMALLOC(old, ipnat_4_1_0_t *);
3158			if (old == NULL) {
3159				IPFERROR(140055);
3160				error = ENOMEM;
3161				break;
3162			}
3163			ipnat_current_to_4_1_0(ptr, old);
3164			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3165			if (error != 0) {
3166				IPFERROR(140056);
3167			}
3168			KFREE(old);
3169		}
3170		break;
3171
3172	case IPFOBJ_NATSTAT :
3173		if (obj->ipfo_rev >= 4013200) {
3174			natstat_4_1_32_t *old;
3175
3176			KMALLOC(old, natstat_4_1_32_t *);
3177			if (old == NULL) {
3178				IPFERROR(140057);
3179				error = ENOMEM;
3180				break;
3181			}
3182			natstat_current_to_4_1_32(ptr, old);
3183			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3184			if (error != 0) {
3185				IPFERROR(140058);
3186			}
3187			KFREE(old);
3188		} else if (obj->ipfo_rev >= 4012700) {
3189			natstat_4_1_27_t *old;
3190
3191			KMALLOC(old, natstat_4_1_27_t *);
3192			if (old == NULL) {
3193				IPFERROR(140059);
3194				error = ENOMEM;
3195				break;
3196			}
3197			natstat_current_to_4_1_27(ptr, old);
3198			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3199			if (error != 0) {
3200				IPFERROR(140060);
3201			}
3202			KFREE(old);
3203		} else if (obj->ipfo_rev >= 4011600) {
3204			natstat_4_1_16_t *old;
3205
3206			KMALLOC(old, natstat_4_1_16_t *);
3207			if (old == NULL) {
3208				IPFERROR(140061);
3209				error = ENOMEM;
3210				break;
3211			}
3212			natstat_current_to_4_1_16(ptr, old);
3213			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3214			if (error != 0) {
3215				IPFERROR(140062);
3216			}
3217			KFREE(old);
3218		} else {
3219			natstat_4_1_0_t *old;
3220
3221			KMALLOC(old, natstat_4_1_0_t *);
3222			if (old == NULL) {
3223				IPFERROR(140063);
3224				error = ENOMEM;
3225				break;
3226			}
3227			natstat_current_to_4_1_0(ptr, old);
3228			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3229			if (error != 0) {
3230				IPFERROR(140064);
3231			}
3232			KFREE(old);
3233		}
3234		break;
3235
3236	case IPFOBJ_STATESAVE :
3237		if (obj->ipfo_rev >= 4011600) {
3238			ipstate_save_4_1_16_t *old;
3239
3240			KMALLOC(old, ipstate_save_4_1_16_t *);
3241			if (old == NULL) {
3242				IPFERROR(140065);
3243				error = ENOMEM;
3244				break;
3245			}
3246			ipstate_save_current_to_4_1_16(ptr, old);
3247			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3248			if (error != 0) {
3249				IPFERROR(140066);
3250			}
3251			KFREE(old);
3252		} else {
3253			ipstate_save_4_1_0_t *old;
3254
3255			KMALLOC(old, ipstate_save_4_1_0_t *);
3256			if (old == NULL) {
3257				IPFERROR(140067);
3258				error = ENOMEM;
3259				break;
3260			}
3261			ipstate_save_current_to_4_1_0(ptr, old);
3262			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3263			if (error != 0) {
3264				IPFERROR(140068);
3265			}
3266			KFREE(old);
3267		}
3268		break;
3269
3270	case IPFOBJ_NATSAVE :
3271		if (obj->ipfo_rev >= 4011600) {
3272			nat_save_4_1_16_t *old16;
3273
3274			KMALLOC(old16, nat_save_4_1_16_t *);
3275			if (old16 == NULL) {
3276				IPFERROR(140069);
3277				error = ENOMEM;
3278				break;
3279			}
3280			nat_save_current_to_4_1_16(ptr, old16);
3281			error = COPYOUT(&old16, obj->ipfo_ptr, sizeof(*old16));
3282			if (error != 0) {
3283				IPFERROR(140070);
3284			}
3285			KFREE(old16);
3286		} else if (obj->ipfo_rev >= 4011400) {
3287			nat_save_4_1_14_t *old14;
3288
3289			KMALLOC(old14, nat_save_4_1_14_t *);
3290			if (old14 == NULL) {
3291				IPFERROR(140071);
3292				error = ENOMEM;
3293				break;
3294			}
3295			nat_save_current_to_4_1_14(ptr, old14);
3296			error = COPYOUT(&old14, obj->ipfo_ptr, sizeof(*old14));
3297			if (error != 0) {
3298				IPFERROR(140072);
3299			}
3300			KFREE(old14);
3301		} else if (obj->ipfo_rev >= 4010300) {
3302			nat_save_4_1_3_t *old3;
3303
3304			KMALLOC(old3, nat_save_4_1_3_t *);
3305			if (old3 == NULL) {
3306				IPFERROR(140073);
3307				error = ENOMEM;
3308				break;
3309			}
3310			nat_save_current_to_4_1_3(ptr, old3);
3311			error = COPYOUT(&old3, obj->ipfo_ptr, sizeof(*old3));
3312			if (error != 0) {
3313				IPFERROR(140074);
3314			}
3315			KFREE(old3);
3316		}
3317		break;
3318
3319	case IPFOBJ_IPSTATE :
3320		if (obj->ipfo_rev >= 4011600) {
3321			ipstate_4_1_16_t *old;
3322
3323			KMALLOC(old, ipstate_4_1_16_t *);
3324			if (old == NULL) {
3325				IPFERROR(140075);
3326				error = ENOMEM;
3327				break;
3328			}
3329			ipstate_current_to_4_1_16(ptr, old);
3330			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3331			if (error != 0) {
3332				IPFERROR(140076);
3333			}
3334			KFREE(old);
3335		} else {
3336			ipstate_4_1_0_t *old;
3337
3338			KMALLOC(old, ipstate_4_1_0_t *);
3339			if (old == NULL) {
3340				IPFERROR(140077);
3341				error = ENOMEM;
3342				break;
3343			}
3344			ipstate_current_to_4_1_0(ptr, old);
3345			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3346			if (error != 0) {
3347				IPFERROR(140078);
3348			}
3349			KFREE(old);
3350		}
3351		break;
3352
3353	case IPFOBJ_STATESTAT :
3354		if (obj->ipfo_rev >= 4012100) {
3355			ips_stat_4_1_21_t *old;
3356
3357			KMALLOC(old, ips_stat_4_1_21_t *);
3358			if (old == NULL) {
3359				IPFERROR(140079);
3360				error = ENOMEM;
3361				break;
3362			}
3363			ips_stat_current_to_4_1_21(ptr, old);
3364			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3365			if (error != 0) {
3366				IPFERROR(140080);
3367			}
3368			KFREE(old);
3369		} else {
3370			ips_stat_4_1_0_t *old;
3371
3372			KMALLOC(old, ips_stat_4_1_0_t *);
3373			if (old == NULL) {
3374				IPFERROR(140081);
3375				error = ENOMEM;
3376				break;
3377			}
3378			ips_stat_current_to_4_1_0(ptr, old);
3379			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3380			if (error != 0) {
3381				IPFERROR(140082);
3382			}
3383			KFREE(old);
3384		}
3385		break;
3386
3387	case IPFOBJ_FRAUTH :
3388		if (obj->ipfo_rev >= 4012900) {
3389			frauth_4_1_29_t *old29;
3390
3391			KMALLOC(old29, frauth_4_1_29_t *);
3392			if (old29 == NULL) {
3393				IPFERROR(140083);
3394				error = ENOMEM;
3395				break;
3396			}
3397			frauth_current_to_4_1_29(ptr, old29);
3398			error = COPYOUT(old29, obj->ipfo_ptr, sizeof(*old29));
3399			if (error != 0) {
3400				IPFERROR(140084);
3401			}
3402			KFREE(old29);
3403		} else if (obj->ipfo_rev >= 4012400) {
3404			frauth_4_1_24_t *old24;
3405
3406			KMALLOC(old24, frauth_4_1_24_t *);
3407			if (old24 == NULL) {
3408				IPFERROR(140085);
3409				error = ENOMEM;
3410				break;
3411			}
3412			frauth_current_to_4_1_24(ptr, old24);
3413			error = COPYOUT(old24, obj->ipfo_ptr, sizeof(*old24));
3414			if (error != 0) {
3415				IPFERROR(140086);
3416			}
3417			KFREE(old24);
3418		} else if (obj->ipfo_rev >= 4012300) {
3419			frauth_4_1_23_t *old23;
3420
3421			KMALLOC(old23, frauth_4_1_23_t *);
3422			if (old23 == NULL) {
3423				IPFERROR(140087);
3424				error = ENOMEM;
3425				break;
3426			}
3427			frauth_current_to_4_1_23(ptr, old23);
3428			error = COPYOUT(old23, obj->ipfo_ptr, sizeof(*old23));
3429			if (error != 0) {
3430				IPFERROR(140088);
3431			}
3432			KFREE(old23);
3433		} else if (obj->ipfo_rev >= 4011100) {
3434			frauth_4_1_11_t *old11;
3435
3436			KMALLOC(old11, frauth_4_1_11_t *);
3437			if (old11 == NULL) {
3438				IPFERROR(140089);
3439				error = ENOMEM;
3440				break;
3441			}
3442			frauth_current_to_4_1_11(ptr, old11);
3443			error = COPYOUT(old11, obj->ipfo_ptr, sizeof(*old11));
3444			if (error != 0) {
3445				IPFERROR(140090);
3446			}
3447			KFREE(old11);
3448		}
3449		break;
3450
3451	case IPFOBJ_NAT :
3452		if (obj->ipfo_rev >= 4012500) {
3453			nat_4_1_25_t *old;
3454
3455			KMALLOC(old, nat_4_1_25_t *);
3456			if (old == NULL) {
3457				IPFERROR(140091);
3458				error = ENOMEM;
3459				break;
3460			}
3461			nat_current_to_4_1_25(ptr, old);
3462			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3463			if (error != 0) {
3464				IPFERROR(140092);
3465			}
3466			KFREE(old);
3467		} else if (obj->ipfo_rev >= 4011400) {
3468			nat_4_1_14_t *old;
3469
3470			KMALLOC(old, nat_4_1_14_t *);
3471			if (old == NULL) {
3472				IPFERROR(140093);
3473				error = ENOMEM;
3474				break;
3475			}
3476			nat_current_to_4_1_14(ptr, old);
3477			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3478			if (error != 0) {
3479				IPFERROR(140094);
3480			}
3481			KFREE(old);
3482		} else if (obj->ipfo_rev >= 4010300) {
3483			nat_4_1_3_t *old;
3484
3485			KMALLOC(old, nat_4_1_3_t *);
3486			if (old == NULL) {
3487				IPFERROR(140095);
3488				error = ENOMEM;
3489				break;
3490			}
3491			nat_current_to_4_1_3(ptr, old);
3492			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3493			if (error != 0) {
3494				IPFERROR(140096);
3495			}
3496			KFREE(old);
3497		}
3498		break;
3499
3500	case IPFOBJ_FRIPF :
3501		if (obj->ipfo_rev < 5000000) {
3502			fripf4_t *old;
3503
3504			KMALLOC(old, fripf4_t *);
3505			if (old == NULL) {
3506				IPFERROR(140097);
3507				error = ENOMEM;
3508				break;
3509			}
3510			ipf_v5fripftov4(ptr, old);
3511			error = COPYOUT(old, obj->ipfo_ptr, sizeof(*old));
3512			if (error != 0) {
3513				IPFERROR(140098);
3514			}
3515			KFREE(old);
3516		}
3517		break;
3518	}
3519	return error;
3520}
3521
3522
3523static void
3524friostat_current_to_4_1_33(current, old, rev)
3525	void *current;
3526	friostat_4_1_33_t *old;
3527	int rev;
3528{
3529	friostat_t *fiop = (friostat_t *)current;
3530
3531	bcopy(&fiop->f_st[0].fr_pass, &old->of_st[0], sizeof(old->of_st[0]));
3532	bcopy(&fiop->f_st[1].fr_pass, &old->of_st[1], sizeof(old->of_st[1]));
3533
3534	old->f_ipf[0][0] = fiop->f_ipf[0][0];
3535	old->f_ipf[0][1] = fiop->f_ipf[0][1];
3536	old->f_ipf[1][0] = fiop->f_ipf[1][0];
3537	old->f_ipf[1][1] = fiop->f_ipf[1][1];
3538	old->f_acct[0][0] = fiop->f_acct[0][0];
3539	old->f_acct[0][1] = fiop->f_acct[0][1];
3540	old->f_acct[1][0] = fiop->f_acct[1][0];
3541	old->f_acct[1][1] = fiop->f_acct[1][1];
3542	old->f_ipf6[0][0] = NULL;
3543	old->f_ipf6[0][1] = NULL;
3544	old->f_ipf6[1][0] = NULL;
3545	old->f_ipf6[1][1] = NULL;
3546	old->f_acct6[0][0] = NULL;
3547	old->f_acct6[0][1] = NULL;
3548	old->f_acct6[1][0] = NULL;
3549	old->f_acct6[1][1] = NULL;
3550	old->f_auth = fiop->f_auth;
3551	bcopy(&fiop->f_groups, &old->f_groups, sizeof(old->f_groups));
3552	bcopy(&fiop->f_froute, &old->f_froute, sizeof(old->f_froute));
3553	old->f_ticks = fiop->f_ticks;
3554	bcopy(&fiop->f_locks, &old->f_locks, sizeof(old->f_locks));
3555	old->f_kmutex_sz = 0;
3556	old->f_krwlock_sz = 0;
3557	old->f_defpass = fiop->f_defpass;
3558	old->f_active = fiop->f_active;
3559	old->f_running = fiop->f_running;
3560	old->f_logging = fiop->f_logging;
3561	old->f_features = fiop->f_features;
3562	sprintf(old->f_version, "IP Filter: v%d.%d.%d",
3563		(rev / 1000000) % 100,
3564		(rev / 10000) % 100,
3565		(rev / 100) % 100);
3566}
3567
3568
3569static void
3570friostat_current_to_4_1_0(current, old, rev)
3571	void *current;
3572	friostat_4_1_0_t *old;
3573	int rev;
3574{
3575	friostat_t *fiop = (friostat_t *)current;
3576
3577	bcopy(&fiop->f_st[0].fr_pass, &old->of_st[0], sizeof(old->of_st[0]));
3578	bcopy(&fiop->f_st[1].fr_pass, &old->of_st[1], sizeof(old->of_st[1]));
3579
3580	old->f_ipf[0][0] = fiop->f_ipf[0][0];
3581	old->f_ipf[0][1] = fiop->f_ipf[0][1];
3582	old->f_ipf[1][0] = fiop->f_ipf[1][0];
3583	old->f_ipf[1][1] = fiop->f_ipf[1][1];
3584	old->f_acct[0][0] = fiop->f_acct[0][0];
3585	old->f_acct[0][1] = fiop->f_acct[0][1];
3586	old->f_acct[1][0] = fiop->f_acct[1][0];
3587	old->f_acct[1][1] = fiop->f_acct[1][1];
3588	old->f_ipf6[0][0] = NULL;
3589	old->f_ipf6[0][1] = NULL;
3590	old->f_ipf6[1][0] = NULL;
3591	old->f_ipf6[1][1] = NULL;
3592	old->f_acct6[0][0] = NULL;
3593	old->f_acct6[0][1] = NULL;
3594	old->f_acct6[1][0] = NULL;
3595	old->f_acct6[1][1] = NULL;
3596	old->f_auth = fiop->f_auth;
3597	bcopy(&fiop->f_groups, &old->f_groups, sizeof(old->f_groups));
3598	bcopy(&fiop->f_froute, &old->f_froute, sizeof(old->f_froute));
3599	old->f_ticks = fiop->f_ticks;
3600	old->f_ipf[0][0] = fiop->f_ipf[0][0];
3601	old->f_ipf[0][1] = fiop->f_ipf[0][1];
3602	old->f_ipf[1][0] = fiop->f_ipf[1][0];
3603	old->f_ipf[1][1] = fiop->f_ipf[1][1];
3604	old->f_acct[0][0] = fiop->f_acct[0][0];
3605	old->f_acct[0][1] = fiop->f_acct[0][1];
3606	old->f_acct[1][0] = fiop->f_acct[1][0];
3607	old->f_acct[1][1] = fiop->f_acct[1][1];
3608	old->f_ipf6[0][0] = NULL;
3609	old->f_ipf6[0][1] = NULL;
3610	old->f_ipf6[1][0] = NULL;
3611	old->f_ipf6[1][1] = NULL;
3612	old->f_acct6[0][0] = NULL;
3613	old->f_acct6[0][1] = NULL;
3614	old->f_acct6[1][0] = NULL;
3615	old->f_acct6[1][1] = NULL;
3616	old->f_auth = fiop->f_auth;
3617	bcopy(&fiop->f_groups, &old->f_groups, sizeof(old->f_groups));
3618	bcopy(&fiop->f_froute, &old->f_froute, sizeof(old->f_froute));
3619	old->f_ticks = fiop->f_ticks;
3620	bcopy(&fiop->f_locks, &old->f_locks, sizeof(old->f_locks));
3621	old->f_kmutex_sz = 0;
3622	old->f_krwlock_sz = 0;
3623	old->f_defpass = fiop->f_defpass;
3624	old->f_active = fiop->f_active;
3625	old->f_running = fiop->f_running;
3626	old->f_logging = fiop->f_logging;
3627	old->f_features = fiop->f_features;
3628	sprintf(old->f_version, "IP Filter: v%d.%d.%d",
3629		(rev / 1000000) % 100,
3630		(rev / 10000) % 100,
3631		(rev / 100) % 100);
3632}
3633
3634
3635/*
3636 * nflags is v5 flags, returns v4 flags.
3637 */
3638static int
3639fr_frflags5to4(nflags)
3640	u_32_t nflags;
3641{
3642	u_32_t oflags = 0;
3643
3644	switch (nflags & FR_CMDMASK) {
3645	case FR_CALL :
3646		oflags = 0x0;
3647		break;
3648	case FR_BLOCK :
3649		oflags = 0x1;
3650		break;
3651	case FR_PASS :
3652		oflags = 0x2;
3653		break;
3654	case FR_AUTH :
3655		oflags = 0x3;
3656		break;
3657	case FR_PREAUTH :
3658		oflags = 0x4;
3659		break;
3660	case FR_ACCOUNT :
3661		oflags = 0x5;
3662		break;
3663	case FR_SKIP :
3664		oflags = 0x6;
3665		break;
3666	default :
3667		break;
3668	}
3669
3670	if (nflags & FR_LOG)
3671		oflags |= 0x00010;
3672	if (nflags & FR_CALLNOW)
3673		oflags |= 0x00020;
3674	if (nflags & FR_NOTSRCIP)
3675		oflags |= 0x00080;
3676	if (nflags & FR_NOTDSTIP)
3677		oflags |= 0x00040;
3678	if (nflags & FR_QUICK)
3679		oflags |= 0x00100;
3680	if (nflags & FR_KEEPFRAG)
3681		oflags |= 0x00200;
3682	if (nflags & FR_KEEPSTATE)
3683		oflags |= 0x00400;
3684	if (nflags & FR_FASTROUTE)
3685		oflags |= 0x00800;
3686	if (nflags & FR_RETRST)
3687		oflags |= 0x01000;
3688	if (nflags & FR_RETICMP)
3689		oflags |= 0x02000;
3690	if (nflags & FR_FAKEICMP)
3691		oflags |= 0x03000;
3692	if (nflags & FR_OUTQUE)
3693		oflags |= 0x04000;
3694	if (nflags & FR_INQUE)
3695		oflags |= 0x08000;
3696	if (nflags & FR_LOGBODY)
3697		oflags |= 0x10000;
3698	if (nflags & FR_LOGFIRST)
3699		oflags |= 0x20000;
3700	if (nflags & FR_LOGORBLOCK)
3701		oflags |= 0x40000;
3702	if (nflags & FR_FRSTRICT)
3703		oflags |= 0x100000;
3704	if (nflags & FR_STSTRICT)
3705		oflags |= 0x200000;
3706	if (nflags & FR_NEWISN)
3707		oflags |= 0x400000;
3708	if (nflags & FR_NOICMPERR)
3709		oflags |= 0x800000;
3710	if (nflags & FR_STATESYNC)
3711		oflags |= 0x1000000;
3712	if (nflags & FR_NOMATCH)
3713		oflags |= 0x8000000;
3714	if (nflags & FR_COPIED)
3715		oflags |= 0x40000000;
3716	if (nflags & FR_INACTIVE)
3717		oflags |= 0x80000000;
3718
3719	return oflags;
3720}
3721
3722
3723static void
3724frentry_current_to_4_1_34(current, old)
3725	void *current;
3726	frentry_4_1_34_t *old;
3727{
3728	frentry_t *fr = (frentry_t *)current;
3729
3730	old->fr_lock = fr->fr_lock;
3731	old->fr_next = fr->fr_next;
3732	old->fr_grp = (void *)fr->fr_grp;
3733	old->fr_isc = fr->fr_isc;
3734	old->fr_ifas[0] = fr->fr_ifas[0];
3735	old->fr_ifas[1] = fr->fr_ifas[1];
3736	old->fr_ifas[2] = fr->fr_ifas[2];
3737	old->fr_ifas[3] = fr->fr_ifas[3];
3738	old->fr_ptr = fr->fr_ptr;
3739	old->fr_comment = NULL;
3740	old->fr_ref = fr->fr_ref;
3741	old->fr_statecnt = fr->fr_statecnt;
3742	old->fr_hits = fr->fr_hits;
3743	old->fr_bytes = fr->fr_bytes;
3744	old->fr_lastpkt.tv_sec = fr->fr_lastpkt.tv_sec;
3745	old->fr_lastpkt.tv_usec = fr->fr_lastpkt.tv_usec;
3746	old->fr_curpps = fr->fr_curpps;
3747	old->fr_dun.fru_data = fr->fr_dun.fru_data;
3748	old->fr_func = fr->fr_func;
3749	old->fr_dsize = fr->fr_dsize;
3750	old->fr_pps = fr->fr_pps;
3751	old->fr_statemax = fr->fr_statemax;
3752	old->fr_flineno = fr->fr_flineno;
3753	old->fr_type = fr->fr_type;
3754	old->fr_flags = fr_frflags5to4(fr->fr_flags);
3755	old->fr_logtag = fr->fr_logtag;
3756	old->fr_collect = fr->fr_collect;
3757	old->fr_arg = fr->fr_arg;
3758	old->fr_loglevel = fr->fr_loglevel;
3759	old->fr_age[0] = fr->fr_age[0];
3760	old->fr_age[1] = fr->fr_age[1];
3761	if (fr->fr_family == AF_INET)
3762		old->fr_v = 4;
3763	if (fr->fr_family == AF_INET6)
3764		old->fr_v = 6;
3765	old->fr_icode = fr->fr_icode;
3766	old->fr_cksum = fr->fr_cksum;
3767	old->fr_tifs[0].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3768	old->fr_tifs[1].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3769	old->fr_dif.ofd_ip6 = fr->fr_dif.fd_ip6;
3770	if (fr->fr_ifnames[0] >= 0) {
3771		strncpy(old->fr_ifnames[0], fr->fr_names + fr->fr_ifnames[0],
3772			LIFNAMSIZ);
3773		old->fr_ifnames[0][LIFNAMSIZ - 1] = '\0';
3774	}
3775	if (fr->fr_ifnames[1] >= 0) {
3776		strncpy(old->fr_ifnames[1], fr->fr_names + fr->fr_ifnames[1],
3777			LIFNAMSIZ);
3778		old->fr_ifnames[1][LIFNAMSIZ - 1] = '\0';
3779	}
3780	if (fr->fr_ifnames[2] >= 0) {
3781		strncpy(old->fr_ifnames[2], fr->fr_names + fr->fr_ifnames[2],
3782			LIFNAMSIZ);
3783		old->fr_ifnames[2][LIFNAMSIZ - 1] = '\0';
3784	}
3785	if (fr->fr_ifnames[3] >= 0) {
3786		strncpy(old->fr_ifnames[3], fr->fr_names + fr->fr_ifnames[3],
3787			LIFNAMSIZ);
3788		old->fr_ifnames[3][LIFNAMSIZ - 1] = '\0';
3789	}
3790	if (fr->fr_tifs[0].fd_name >= 0) {
3791		strncpy(old->fr_tifs[0].fd_ifname,
3792			fr->fr_names + fr->fr_tifs[0].fd_name, LIFNAMSIZ);
3793		old->fr_tifs[0].fd_ifname[LIFNAMSIZ - 1] = '\0';
3794	}
3795	if (fr->fr_tifs[1].fd_name >= 0) {
3796		strncpy(old->fr_tifs[1].fd_ifname,
3797			fr->fr_names + fr->fr_tifs[1].fd_name, LIFNAMSIZ);
3798		old->fr_tifs[1].fd_ifname[LIFNAMSIZ - 1] = '\0';
3799	}
3800	if (fr->fr_dif.fd_name >= 0) {
3801		strncpy(old->fr_dif.fd_ifname,
3802			fr->fr_names + fr->fr_dif.fd_name, LIFNAMSIZ);
3803		old->fr_dif.fd_ifname[LIFNAMSIZ - 1] = '\0';
3804	}
3805	if (fr->fr_group >= 0) {
3806		strncpy(old->fr_group, fr->fr_names + fr->fr_group,
3807			FR_GROUPLEN);
3808		old->fr_group[FR_GROUPLEN - 1] = '\0';
3809	}
3810	if (fr->fr_grhead >= 0) {
3811		strncpy(old->fr_grhead, fr->fr_names + fr->fr_grhead,
3812			FR_GROUPLEN);
3813		old->fr_grhead[FR_GROUPLEN - 1] = '\0';
3814	}
3815}
3816
3817
3818static void
3819frentry_current_to_4_1_16(current, old)
3820	void *current;
3821	frentry_4_1_16_t *old;
3822{
3823	frentry_t *fr = (frentry_t *)current;
3824
3825	old->fr_lock = fr->fr_lock;
3826	old->fr_next = fr->fr_next;
3827	old->fr_grp = (void *)fr->fr_grp;
3828	old->fr_isc = fr->fr_isc;
3829	old->fr_ifas[0] = fr->fr_ifas[0];
3830	old->fr_ifas[1] = fr->fr_ifas[1];
3831	old->fr_ifas[2] = fr->fr_ifas[2];
3832	old->fr_ifas[3] = fr->fr_ifas[3];
3833	old->fr_ptr = fr->fr_ptr;
3834	old->fr_comment = NULL;
3835	old->fr_ref = fr->fr_ref;
3836	old->fr_statecnt = fr->fr_statecnt;
3837	old->fr_hits = fr->fr_hits;
3838	old->fr_bytes = fr->fr_bytes;
3839	old->fr_lastpkt.tv_sec = fr->fr_lastpkt.tv_sec;
3840	old->fr_lastpkt.tv_usec = fr->fr_lastpkt.tv_usec;
3841	old->fr_curpps = fr->fr_curpps;
3842	old->fr_dun.fru_data = fr->fr_dun.fru_data;
3843	old->fr_func = fr->fr_func;
3844	old->fr_dsize = fr->fr_dsize;
3845	old->fr_pps = fr->fr_pps;
3846	old->fr_statemax = fr->fr_statemax;
3847	old->fr_flineno = fr->fr_flineno;
3848	old->fr_type = fr->fr_type;
3849	old->fr_flags = fr_frflags5to4(fr->fr_flags);
3850	old->fr_logtag = fr->fr_logtag;
3851	old->fr_collect = fr->fr_collect;
3852	old->fr_arg = fr->fr_arg;
3853	old->fr_loglevel = fr->fr_loglevel;
3854	old->fr_age[0] = fr->fr_age[0];
3855	old->fr_age[1] = fr->fr_age[1];
3856	if (old->fr_v == 4)
3857		fr->fr_family = AF_INET;
3858	if (old->fr_v == 6)
3859		fr->fr_family = AF_INET6;
3860	old->fr_icode = fr->fr_icode;
3861	old->fr_cksum = fr->fr_cksum;
3862	old->fr_tifs[0].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3863	old->fr_tifs[1].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3864	old->fr_dif.ofd_ip6 = fr->fr_dif.fd_ip6;
3865	if (fr->fr_ifnames[0] >= 0) {
3866		strncpy(old->fr_ifnames[0], fr->fr_names + fr->fr_ifnames[0],
3867			LIFNAMSIZ);
3868		old->fr_ifnames[0][LIFNAMSIZ - 1] = '\0';
3869	}
3870	if (fr->fr_ifnames[1] >= 0) {
3871		strncpy(old->fr_ifnames[1], fr->fr_names + fr->fr_ifnames[1],
3872			LIFNAMSIZ);
3873		old->fr_ifnames[1][LIFNAMSIZ - 1] = '\0';
3874	}
3875	if (fr->fr_ifnames[2] >= 0) {
3876		strncpy(old->fr_ifnames[2], fr->fr_names + fr->fr_ifnames[2],
3877			LIFNAMSIZ);
3878		old->fr_ifnames[2][LIFNAMSIZ - 1] = '\0';
3879	}
3880	if (fr->fr_ifnames[3] >= 0) {
3881		strncpy(old->fr_ifnames[3], fr->fr_names + fr->fr_ifnames[3],
3882			LIFNAMSIZ);
3883		old->fr_ifnames[3][LIFNAMSIZ - 1] = '\0';
3884	}
3885	if (fr->fr_tifs[0].fd_name >= 0) {
3886		strncpy(old->fr_tifs[0].fd_ifname,
3887			fr->fr_names + fr->fr_tifs[0].fd_name, LIFNAMSIZ);
3888		old->fr_tifs[0].fd_ifname[LIFNAMSIZ - 1] = '\0';
3889	}
3890	if (fr->fr_tifs[1].fd_name >= 0) {
3891		strncpy(old->fr_tifs[1].fd_ifname,
3892			fr->fr_names + fr->fr_tifs[1].fd_name, LIFNAMSIZ);
3893		old->fr_tifs[1].fd_ifname[LIFNAMSIZ - 1] = '\0';
3894	}
3895	if (fr->fr_dif.fd_name >= 0) {
3896		strncpy(old->fr_dif.fd_ifname,
3897			fr->fr_names + fr->fr_dif.fd_name, LIFNAMSIZ);
3898		old->fr_dif.fd_ifname[LIFNAMSIZ - 1] = '\0';
3899	}
3900	if (fr->fr_group >= 0) {
3901		strncpy(old->fr_group, fr->fr_names + fr->fr_group,
3902			FR_GROUPLEN);
3903		old->fr_group[FR_GROUPLEN - 1] = '\0';
3904	}
3905	if (fr->fr_grhead >= 0) {
3906		strncpy(old->fr_grhead, fr->fr_names + fr->fr_grhead,
3907			FR_GROUPLEN);
3908		old->fr_grhead[FR_GROUPLEN - 1] = '\0';
3909	}
3910}
3911
3912
3913static void
3914frentry_current_to_4_1_0(current, old)
3915	void *current;
3916	frentry_4_1_0_t *old;
3917{
3918	frentry_t *fr = (frentry_t *)current;
3919
3920	old->fr_lock = fr->fr_lock;
3921	old->fr_next = fr->fr_next;
3922	old->fr_grp = (void *)fr->fr_grp;
3923	old->fr_isc = fr->fr_isc;
3924	old->fr_ifas[0] = fr->fr_ifas[0];
3925	old->fr_ifas[1] = fr->fr_ifas[1];
3926	old->fr_ifas[2] = fr->fr_ifas[2];
3927	old->fr_ifas[3] = fr->fr_ifas[3];
3928	old->fr_ptr = fr->fr_ptr;
3929	old->fr_comment = NULL;
3930	old->fr_ref = fr->fr_ref;
3931	old->fr_statecnt = fr->fr_statecnt;
3932	old->fr_hits = fr->fr_hits;
3933	old->fr_bytes = fr->fr_bytes;
3934	old->fr_lastpkt.tv_sec = fr->fr_lastpkt.tv_sec;
3935	old->fr_lastpkt.tv_usec = fr->fr_lastpkt.tv_usec;
3936	old->fr_curpps = fr->fr_curpps;
3937	old->fr_dun.fru_data = fr->fr_dun.fru_data;
3938	old->fr_func = fr->fr_func;
3939	old->fr_dsize = fr->fr_dsize;
3940	old->fr_pps = fr->fr_pps;
3941	old->fr_statemax = fr->fr_statemax;
3942	old->fr_flineno = fr->fr_flineno;
3943	old->fr_type = fr->fr_type;
3944	old->fr_flags = fr_frflags5to4(fr->fr_flags);
3945	old->fr_logtag = fr->fr_logtag;
3946	old->fr_collect = fr->fr_collect;
3947	old->fr_arg = fr->fr_arg;
3948	old->fr_loglevel = fr->fr_loglevel;
3949	old->fr_age[0] = fr->fr_age[0];
3950	old->fr_age[1] = fr->fr_age[1];
3951	if (old->fr_v == 4)
3952		fr->fr_family = AF_INET;
3953	if (old->fr_v == 6)
3954		fr->fr_family = AF_INET6;
3955	old->fr_icode = fr->fr_icode;
3956	old->fr_cksum = fr->fr_cksum;
3957	old->fr_tifs[0].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3958	old->fr_tifs[1].ofd_ip6 = fr->fr_tifs[0].fd_ip6;
3959	old->fr_dif.ofd_ip6 = fr->fr_dif.fd_ip6;
3960	if (fr->fr_ifnames[0] >= 0) {
3961		strncpy(old->fr_ifnames[0], fr->fr_names + fr->fr_ifnames[0],
3962			LIFNAMSIZ);
3963		old->fr_ifnames[0][LIFNAMSIZ - 1] = '\0';
3964	}
3965	if (fr->fr_ifnames[1] >= 0) {
3966		strncpy(old->fr_ifnames[1], fr->fr_names + fr->fr_ifnames[1],
3967			LIFNAMSIZ);
3968		old->fr_ifnames[1][LIFNAMSIZ - 1] = '\0';
3969	}
3970	if (fr->fr_ifnames[2] >= 0) {
3971		strncpy(old->fr_ifnames[2], fr->fr_names + fr->fr_ifnames[2],
3972			LIFNAMSIZ);
3973		old->fr_ifnames[2][LIFNAMSIZ - 1] = '\0';
3974	}
3975	if (fr->fr_ifnames[3] >= 0) {
3976		strncpy(old->fr_ifnames[3], fr->fr_names + fr->fr_ifnames[3],
3977			LIFNAMSIZ);
3978		old->fr_ifnames[3][LIFNAMSIZ - 1] = '\0';
3979	}
3980	if (fr->fr_tifs[0].fd_name >= 0) {
3981		strncpy(old->fr_tifs[0].fd_ifname,
3982			fr->fr_names + fr->fr_tifs[0].fd_name, LIFNAMSIZ);
3983		old->fr_tifs[0].fd_ifname[LIFNAMSIZ - 1] = '\0';
3984	}
3985	if (fr->fr_tifs[1].fd_name >= 0) {
3986		strncpy(old->fr_tifs[1].fd_ifname,
3987			fr->fr_names + fr->fr_tifs[1].fd_name, LIFNAMSIZ);
3988		old->fr_tifs[1].fd_ifname[LIFNAMSIZ - 1] = '\0';
3989	}
3990	if (fr->fr_dif.fd_name >= 0) {
3991		strncpy(old->fr_dif.fd_ifname,
3992			fr->fr_names + fr->fr_dif.fd_name, LIFNAMSIZ);
3993		old->fr_dif.fd_ifname[LIFNAMSIZ - 1] = '\0';
3994	}
3995	if (fr->fr_group >= 0) {
3996		strncpy(old->fr_group, fr->fr_names + fr->fr_group,
3997			FR_GROUPLEN);
3998		old->fr_group[FR_GROUPLEN - 1] = '\0';
3999	}
4000	if (fr->fr_grhead >= 0) {
4001		strncpy(old->fr_grhead, fr->fr_names + fr->fr_grhead,
4002			FR_GROUPLEN);
4003		old->fr_grhead[FR_GROUPLEN - 1] = '\0';
4004	}
4005}
4006
4007
4008static void
4009fr_info_current_to_4_1_24(current, old)
4010	void *current;
4011	fr_info_4_1_24_t *old;
4012{
4013	fr_info_t *fin = (fr_info_t *)current;
4014
4015	old->fin_ifp = fin->fin_ifp;
4016	ipf_v5iptov4(&fin->fin_fi, &old->fin_fi);
4017	bcopy(&fin->fin_dat, &old->fin_dat, sizeof(fin->fin_dat));
4018	old->fin_out = fin->fin_out;
4019	old->fin_rev = fin->fin_rev;
4020	old->fin_hlen = fin->fin_hlen;
4021	old->ofin_tcpf = fin->fin_tcpf;
4022	old->fin_icode = fin->fin_icode;
4023	old->fin_rule = fin->fin_rule;
4024	bcopy(fin->fin_group, old->fin_group, sizeof(fin->fin_group));
4025	old->fin_fr = fin->fin_fr;
4026	old->fin_dp = fin->fin_dp;
4027	old->fin_dlen = fin->fin_dlen;
4028	old->fin_plen = fin->fin_plen;
4029	old->fin_ipoff = fin->fin_ipoff;
4030	old->fin_id = fin->fin_id;
4031	old->fin_off = fin->fin_off;
4032	old->fin_depth = fin->fin_depth;
4033	old->fin_error = fin->fin_error;
4034	old->fin_cksum = fin->fin_cksum;
4035	old->fin_state = NULL;
4036	old->fin_nat = NULL;
4037	old->fin_nattag = fin->fin_nattag;
4038	old->fin_exthdr = NULL;
4039	old->ofin_ip = fin->fin_ip;
4040	old->fin_mp = fin->fin_mp;
4041	old->fin_m = fin->fin_m;
4042#if SOLARIS
4043	old->fin_qfm = fin->fin_qfm;
4044	old->fin_qpi = fin->fin_qpi;
4045	old->fin_ifname[0] = '\0';
4046#endif
4047}
4048
4049
4050static void
4051fr_info_current_to_4_1_23(current, old)
4052	void *current;
4053	fr_info_4_1_23_t *old;
4054{
4055	fr_info_t *fin = (fr_info_t *)current;
4056
4057	old->fin_ifp = fin->fin_ifp;
4058	ipf_v5iptov4(&fin->fin_fi, &old->fin_fi);
4059	bcopy(&fin->fin_dat, &old->fin_dat, sizeof(fin->fin_dat));
4060	old->fin_out = fin->fin_out;
4061	old->fin_rev = fin->fin_rev;
4062	old->fin_hlen = fin->fin_hlen;
4063	old->ofin_tcpf = fin->fin_tcpf;
4064	old->fin_icode = fin->fin_icode;
4065	old->fin_rule = fin->fin_rule;
4066	bcopy(fin->fin_group, old->fin_group, sizeof(fin->fin_group));
4067	old->fin_fr = fin->fin_fr;
4068	old->fin_dp = fin->fin_dp;
4069	old->fin_dlen = fin->fin_dlen;
4070	old->fin_plen = fin->fin_plen;
4071	old->fin_ipoff = fin->fin_ipoff;
4072	old->fin_id = fin->fin_id;
4073	old->fin_off = fin->fin_off;
4074	old->fin_depth = fin->fin_depth;
4075	old->fin_error = fin->fin_error;
4076	old->fin_state = NULL;
4077	old->fin_nat = NULL;
4078	old->fin_nattag = fin->fin_nattag;
4079	old->ofin_ip = fin->fin_ip;
4080	old->fin_mp = fin->fin_mp;
4081	old->fin_m = fin->fin_m;
4082#if SOLARIS
4083	old->fin_qfm = fin->fin_qfm;
4084	old->fin_qpi = fin->fin_qpi;
4085	old->fin_ifname[0] = '\0';
4086#endif
4087}
4088
4089
4090static void
4091fr_info_current_to_4_1_11(current, old)
4092	void *current;
4093	fr_info_4_1_11_t *old;
4094{
4095	fr_info_t *fin = (fr_info_t *)current;
4096
4097	old->fin_ifp = fin->fin_ifp;
4098	ipf_v5iptov4(&fin->fin_fi, &old->fin_fi);
4099	bcopy(&fin->fin_dat, &old->fin_dat, sizeof(fin->fin_dat));
4100	old->fin_out = fin->fin_out;
4101	old->fin_rev = fin->fin_rev;
4102	old->fin_hlen = fin->fin_hlen;
4103	old->ofin_tcpf = fin->fin_tcpf;
4104	old->fin_icode = fin->fin_icode;
4105	old->fin_rule = fin->fin_rule;
4106	bcopy(fin->fin_group, old->fin_group, sizeof(fin->fin_group));
4107	old->fin_fr = fin->fin_fr;
4108	old->fin_dp = fin->fin_dp;
4109	old->fin_dlen = fin->fin_dlen;
4110	old->fin_plen = fin->fin_plen;
4111	old->fin_ipoff = fin->fin_ipoff;
4112	old->fin_id = fin->fin_id;
4113	old->fin_off = fin->fin_off;
4114	old->fin_depth = fin->fin_depth;
4115	old->fin_error = fin->fin_error;
4116	old->fin_state = NULL;
4117	old->fin_nat = NULL;
4118	old->fin_nattag = fin->fin_nattag;
4119	old->ofin_ip = fin->fin_ip;
4120	old->fin_mp = fin->fin_mp;
4121	old->fin_m = fin->fin_m;
4122#if SOLARIS
4123	old->fin_qfm = fin->fin_qfm;
4124	old->fin_qpi = fin->fin_qpi;
4125	old->fin_ifname[0] = '\0';
4126#endif
4127}
4128
4129
4130static void
4131frauth_current_to_4_1_29(current, old)
4132	void *current;
4133	frauth_4_1_29_t *old;
4134{
4135	frauth_t *fra = (frauth_t *)current;
4136
4137	old->fra_age = fra->fra_age;
4138	old->fra_len = fra->fra_len;
4139	old->fra_index = fra->fra_index;
4140	old->fra_pass = fra->fra_pass;
4141	fr_info_current_to_4_1_24(&fra->fra_info, &old->fra_info);
4142	old->fra_buf = fra->fra_buf;
4143	old->fra_flx = fra->fra_flx;
4144#if SOLARIS
4145	old->fra_q = fra->fra_q;
4146	old->fra_m = fra->fra_m;
4147#endif
4148}
4149
4150
4151static void
4152frauth_current_to_4_1_24(current, old)
4153	void *current;
4154	frauth_4_1_24_t *old;
4155{
4156	frauth_t *fra = (frauth_t *)current;
4157
4158	old->fra_age = fra->fra_age;
4159	old->fra_len = fra->fra_len;
4160	old->fra_index = fra->fra_index;
4161	old->fra_pass = fra->fra_pass;
4162	fr_info_current_to_4_1_24(&fra->fra_info, &old->fra_info);
4163	old->fra_buf = fra->fra_buf;
4164#if SOLARIS
4165	old->fra_q = fra->fra_q;
4166	old->fra_m = fra->fra_m;
4167#endif
4168}
4169
4170
4171static void
4172frauth_current_to_4_1_23(current, old)
4173	void *current;
4174	frauth_4_1_23_t *old;
4175{
4176	frauth_t *fra = (frauth_t *)current;
4177
4178	old->fra_age = fra->fra_age;
4179	old->fra_len = fra->fra_len;
4180	old->fra_index = fra->fra_index;
4181	old->fra_pass = fra->fra_pass;
4182	fr_info_current_to_4_1_23(&fra->fra_info, &old->fra_info);
4183	old->fra_buf = fra->fra_buf;
4184#if SOLARIS
4185	old->fra_q = fra->fra_q;
4186	old->fra_m = fra->fra_m;
4187#endif
4188}
4189
4190
4191static void
4192frauth_current_to_4_1_11(current, old)
4193	void *current;
4194	frauth_4_1_11_t *old;
4195{
4196	frauth_t *fra = (frauth_t *)current;
4197
4198	old->fra_age = fra->fra_age;
4199	old->fra_len = fra->fra_len;
4200	old->fra_index = fra->fra_index;
4201	old->fra_pass = fra->fra_pass;
4202	fr_info_current_to_4_1_11(&fra->fra_info, &old->fra_info);
4203	old->fra_buf = fra->fra_buf;
4204#if SOLARIS
4205	old->fra_q = fra->fra_q;
4206	old->fra_m = fra->fra_m;
4207#endif
4208}
4209
4210
4211static void
4212ipnat_current_to_4_1_14(current, old)
4213	void *current;
4214	ipnat_4_1_14_t *old;
4215{
4216	ipnat_t *np = (ipnat_t *)current;
4217
4218	old->in_next = np->in_next;
4219	old->in_rnext = np->in_rnext;
4220	old->in_prnext = np->in_prnext;
4221	old->in_mnext = np->in_mnext;
4222	old->in_pmnext = np->in_pmnext;
4223	old->in_tqehead[0] = np->in_tqehead[0];
4224	old->in_tqehead[1] = np->in_tqehead[1];
4225	old->in_ifps[0] = np->in_ifps[0];
4226	old->in_ifps[1] = np->in_ifps[1];
4227	old->in_apr = np->in_apr;
4228	old->in_comment = np->in_comment;
4229	old->in_space = np->in_space;
4230	old->in_hits = np->in_hits;
4231	old->in_use = np->in_use;
4232	old->in_hv = np->in_hv[0];
4233	old->in_flineno = np->in_flineno;
4234	if (old->in_redir == NAT_REDIRECT)
4235		old->in_pnext = np->in_dpnext;
4236	else
4237		old->in_pnext = np->in_spnext;
4238	old->in_v = np->in_v[0];
4239	old->in_flags = np->in_flags;
4240	old->in_mssclamp = np->in_mssclamp;
4241	old->in_age[0] = np->in_age[0];
4242	old->in_age[1] = np->in_age[1];
4243	old->in_redir = np->in_redir;
4244	old->in_p = np->in_pr[0];
4245	if (np->in_redir == NAT_REDIRECT) {
4246		old->in_next6 = np->in_ndst.na_nextaddr;
4247		old->in_in[0] = np->in_ndst.na_addr[0];
4248		old->in_in[1] = np->in_ndst.na_addr[1];
4249		old->in_out[0] = np->in_odst.na_addr[0];
4250		old->in_out[1] = np->in_odst.na_addr[1];
4251		old->in_src[0] = np->in_osrc.na_addr[0];
4252		old->in_src[1] = np->in_osrc.na_addr[1];
4253	} else {
4254		old->in_next6 = np->in_nsrc.na_nextaddr;
4255		old->in_out[0] = np->in_nsrc.na_addr[0];
4256		old->in_out[1] = np->in_nsrc.na_addr[1];
4257		old->in_in[0] = np->in_osrc.na_addr[0];
4258		old->in_in[1] = np->in_osrc.na_addr[1];
4259		old->in_src[0] = np->in_odst.na_addr[0];
4260		old->in_src[1] = np->in_odst.na_addr[1];
4261	}
4262	ipfv5tuctov4(&np->in_tuc, &old->in_tuc);
4263	if (np->in_redir == NAT_REDIRECT) {
4264		old->in_port[0] = np->in_dpmin;
4265		old->in_port[1] = np->in_dpmax;
4266	} else {
4267		old->in_port[0] = np->in_spmin;
4268		old->in_port[1] = np->in_spmax;
4269	}
4270	old->in_ppip = np->in_ppip;
4271	old->in_ippip = np->in_ippip;
4272	bcopy(&np->in_tag, &old->in_tag, sizeof(np->in_tag));
4273
4274	if (np->in_ifnames[0] >= 0) {
4275		strncpy(old->in_ifnames[0], np->in_names + np->in_ifnames[0],
4276			LIFNAMSIZ);
4277		old->in_ifnames[0][LIFNAMSIZ - 1] = '\0';
4278	}
4279	if (np->in_ifnames[1] >= 0) {
4280		strncpy(old->in_ifnames[1], np->in_names + np->in_ifnames[1],
4281			LIFNAMSIZ);
4282		old->in_ifnames[1][LIFNAMSIZ - 1] = '\0';
4283	}
4284	if (np->in_plabel >= 0) {
4285		strncpy(old->in_plabel, np->in_names + np->in_plabel,
4286			APR_LABELLEN);
4287		old->in_plabel[APR_LABELLEN - 1] = '\0';
4288	}
4289}
4290
4291
4292static void
4293ipnat_current_to_4_1_0(current, old)
4294	void *current;
4295	ipnat_4_1_0_t *old;
4296{
4297	ipnat_t *np = (ipnat_t *)current;
4298
4299	old->in_next = np->in_next;
4300	old->in_rnext = np->in_rnext;
4301	old->in_prnext = np->in_prnext;
4302	old->in_mnext = np->in_mnext;
4303	old->in_pmnext = np->in_pmnext;
4304	old->in_tqehead[0] = np->in_tqehead[0];
4305	old->in_tqehead[1] = np->in_tqehead[1];
4306	old->in_ifps[0] = np->in_ifps[0];
4307	old->in_ifps[1] = np->in_ifps[1];
4308	old->in_apr = np->in_apr;
4309	old->in_comment = np->in_comment;
4310	old->in_space = np->in_space;
4311	old->in_hits = np->in_hits;
4312	old->in_use = np->in_use;
4313	old->in_hv = np->in_hv[0];
4314	old->in_flineno = np->in_flineno;
4315	if (old->in_redir == NAT_REDIRECT)
4316		old->in_pnext = np->in_dpnext;
4317	else
4318		old->in_pnext = np->in_spnext;
4319	old->in_v = np->in_v[0];
4320	old->in_flags = np->in_flags;
4321	old->in_mssclamp = np->in_mssclamp;
4322	old->in_age[0] = np->in_age[0];
4323	old->in_age[1] = np->in_age[1];
4324	old->in_redir = np->in_redir;
4325	old->in_p = np->in_pr[0];
4326	if (np->in_redir == NAT_REDIRECT) {
4327		old->in_next6 = np->in_ndst.na_nextaddr;
4328		old->in_in[0] = np->in_ndst.na_addr[0];
4329		old->in_in[1] = np->in_ndst.na_addr[1];
4330		old->in_out[0] = np->in_odst.na_addr[0];
4331		old->in_out[1] = np->in_odst.na_addr[1];
4332		old->in_src[0] = np->in_osrc.na_addr[0];
4333		old->in_src[1] = np->in_osrc.na_addr[1];
4334	} else {
4335		old->in_next6 = np->in_nsrc.na_nextaddr;
4336		old->in_out[0] = np->in_nsrc.na_addr[0];
4337		old->in_out[1] = np->in_nsrc.na_addr[1];
4338		old->in_in[0] = np->in_osrc.na_addr[0];
4339		old->in_in[1] = np->in_osrc.na_addr[1];
4340		old->in_src[0] = np->in_odst.na_addr[0];
4341		old->in_src[1] = np->in_odst.na_addr[1];
4342	}
4343	ipfv5tuctov4(&np->in_tuc, &old->in_tuc);
4344	if (np->in_redir == NAT_REDIRECT) {
4345		old->in_port[0] = np->in_dpmin;
4346		old->in_port[1] = np->in_dpmax;
4347	} else {
4348		old->in_port[0] = np->in_spmin;
4349		old->in_port[1] = np->in_spmax;
4350	}
4351	old->in_ppip = np->in_ppip;
4352	old->in_ippip = np->in_ippip;
4353	bcopy(&np->in_tag, &old->in_tag, sizeof(np->in_tag));
4354
4355	if (np->in_ifnames[0] >= 0) {
4356		strncpy(old->in_ifnames[0], np->in_names + np->in_ifnames[0],
4357			LIFNAMSIZ);
4358		old->in_ifnames[0][LIFNAMSIZ - 1] = '\0';
4359	}
4360	if (np->in_ifnames[1] >= 0) {
4361		strncpy(old->in_ifnames[1], np->in_names + np->in_ifnames[1],
4362			LIFNAMSIZ);
4363		old->in_ifnames[1][LIFNAMSIZ - 1] = '\0';
4364	}
4365	if (np->in_plabel >= 0) {
4366		strncpy(old->in_plabel, np->in_names + np->in_plabel,
4367			APR_LABELLEN);
4368		old->in_plabel[APR_LABELLEN - 1] = '\0';
4369	}
4370}
4371
4372
4373static void
4374ipstate_current_to_4_1_16(current, old)
4375	void *current;
4376	ipstate_4_1_16_t *old;
4377{
4378	ipstate_t *is = (ipstate_t *)current;
4379
4380	old->is_lock = is->is_lock;
4381	old->is_next = is->is_next;
4382	old->is_pnext = is->is_pnext;
4383	old->is_hnext = is->is_hnext;
4384	old->is_phnext = is->is_phnext;
4385	old->is_me = is->is_me;
4386	old->is_ifp[0] = is->is_ifp[0];
4387	old->is_ifp[1] = is->is_ifp[1];
4388	old->is_sync = is->is_sync;
4389	old->is_rule = is->is_rule;
4390	old->is_tqehead[0] = is->is_tqehead[0];
4391	old->is_tqehead[1] = is->is_tqehead[1];
4392	old->is_isc = is->is_isc;
4393	old->is_pkts[0] = is->is_pkts[0];
4394	old->is_pkts[1] = is->is_pkts[1];
4395	old->is_pkts[2] = is->is_pkts[2];
4396	old->is_pkts[3] = is->is_pkts[3];
4397	old->is_bytes[0] = is->is_bytes[0];
4398	old->is_bytes[1] = is->is_bytes[1];
4399	old->is_bytes[2] = is->is_bytes[2];
4400	old->is_bytes[3] = is->is_bytes[3];
4401	old->is_icmppkts[0] = is->is_icmppkts[0];
4402	old->is_icmppkts[1] = is->is_icmppkts[1];
4403	old->is_icmppkts[2] = is->is_icmppkts[2];
4404	old->is_icmppkts[3] = is->is_icmppkts[3];
4405	old->is_sti = is->is_sti;
4406	old->is_frage[0] = is->is_frage[0];
4407	old->is_frage[1] = is->is_frage[1];
4408	old->is_ref = is->is_ref;
4409	old->is_isninc[0] = is->is_isninc[0];
4410	old->is_isninc[1] = is->is_isninc[1];
4411	old->is_sumd[0] = is->is_sumd[0];
4412	old->is_sumd[1] = is->is_sumd[1];
4413	old->is_src = is->is_src;
4414	old->is_dst = is->is_dst;
4415	old->is_pass = is->is_pass;
4416	old->is_p = is->is_p;
4417	old->is_v = is->is_v;
4418	old->is_hv = is->is_hv;
4419	old->is_tag = is->is_tag;
4420	old->is_opt[0] = is->is_opt[0];
4421	old->is_opt[1] = is->is_opt[1];
4422	old->is_optmsk[0] = is->is_optmsk[0];
4423	old->is_optmsk[1] = is->is_optmsk[1];
4424	old->is_sec = is->is_sec;
4425	old->is_secmsk = is->is_secmsk;
4426	old->is_auth = is->is_auth;
4427	old->is_authmsk = is->is_authmsk;
4428	ipf_v5tcpinfoto4(&is->is_tcp, &old->is_tcp);
4429	old->is_flags = is->is_flags;
4430	old->is_flx[0][0] = is->is_flx[0][0];
4431	old->is_flx[0][1] = is->is_flx[0][1];
4432	old->is_flx[1][0] = is->is_flx[1][0];
4433	old->is_flx[1][1] = is->is_flx[1][1];
4434	old->is_rulen = is->is_rulen;
4435	old->is_s0[0] = is->is_s0[0];
4436	old->is_s0[1] = is->is_s0[1];
4437	old->is_smsk[0] = is->is_smsk[0];
4438	old->is_smsk[1] = is->is_smsk[1];
4439	bcopy(is->is_group, old->is_group, sizeof(is->is_group));
4440	bcopy(is->is_sbuf, old->is_sbuf, sizeof(is->is_sbuf));
4441	bcopy(is->is_ifname, old->is_ifname, sizeof(is->is_ifname));
4442}
4443
4444
4445static void
4446ipstate_current_to_4_1_0(current, old)
4447	void *current;
4448	ipstate_4_1_0_t *old;
4449{
4450	ipstate_t *is = (ipstate_t *)current;
4451
4452	old->is_lock = is->is_lock;
4453	old->is_next = is->is_next;
4454	old->is_pnext = is->is_pnext;
4455	old->is_hnext = is->is_hnext;
4456	old->is_phnext = is->is_phnext;
4457	old->is_me = is->is_me;
4458	old->is_ifp[0] = is->is_ifp[0];
4459	old->is_ifp[1] = is->is_ifp[1];
4460	old->is_sync = is->is_sync;
4461	bzero(&old->is_nat, sizeof(old->is_nat));
4462	old->is_rule = is->is_rule;
4463	old->is_tqehead[0] = is->is_tqehead[0];
4464	old->is_tqehead[1] = is->is_tqehead[1];
4465	old->is_isc = is->is_isc;
4466	old->is_pkts[0] = is->is_pkts[0];
4467	old->is_pkts[1] = is->is_pkts[1];
4468	old->is_pkts[2] = is->is_pkts[2];
4469	old->is_pkts[3] = is->is_pkts[3];
4470	old->is_bytes[0] = is->is_bytes[0];
4471	old->is_bytes[1] = is->is_bytes[1];
4472	old->is_bytes[2] = is->is_bytes[2];
4473	old->is_bytes[3] = is->is_bytes[3];
4474	old->is_icmppkts[0] = is->is_icmppkts[0];
4475	old->is_icmppkts[1] = is->is_icmppkts[1];
4476	old->is_icmppkts[2] = is->is_icmppkts[2];
4477	old->is_icmppkts[3] = is->is_icmppkts[3];
4478	old->is_sti = is->is_sti;
4479	old->is_frage[0] = is->is_frage[0];
4480	old->is_frage[1] = is->is_frage[1];
4481	old->is_ref = is->is_ref;
4482	old->is_isninc[0] = is->is_isninc[0];
4483	old->is_isninc[1] = is->is_isninc[1];
4484	old->is_sumd[0] = is->is_sumd[0];
4485	old->is_sumd[1] = is->is_sumd[1];
4486	old->is_src = is->is_src;
4487	old->is_dst = is->is_dst;
4488	old->is_pass = is->is_pass;
4489	old->is_p = is->is_p;
4490	old->is_v = is->is_v;
4491	old->is_hv = is->is_hv;
4492	old->is_tag = is->is_tag;
4493	old->is_opt[0] = is->is_opt[0];
4494	old->is_opt[1] = is->is_opt[1];
4495	old->is_optmsk[0] = is->is_optmsk[0];
4496	old->is_optmsk[1] = is->is_optmsk[1];
4497	old->is_sec = is->is_sec;
4498	old->is_secmsk = is->is_secmsk;
4499	old->is_auth = is->is_auth;
4500	old->is_authmsk = is->is_authmsk;
4501	ipf_v5tcpinfoto4(&is->is_tcp, &old->is_tcp);
4502	old->is_flags = is->is_flags;
4503	old->is_flx[0][0] = is->is_flx[0][0];
4504	old->is_flx[0][1] = is->is_flx[0][1];
4505	old->is_flx[1][0] = is->is_flx[1][0];
4506	old->is_flx[1][1] = is->is_flx[1][1];
4507	old->is_rulen = is->is_rulen;
4508	old->is_s0[0] = is->is_s0[0];
4509	old->is_s0[1] = is->is_s0[1];
4510	old->is_smsk[0] = is->is_smsk[0];
4511	old->is_smsk[1] = is->is_smsk[1];
4512	bcopy(is->is_group, old->is_group, sizeof(is->is_group));
4513	bcopy(is->is_sbuf, old->is_sbuf, sizeof(is->is_sbuf));
4514	bcopy(is->is_ifname, old->is_ifname, sizeof(is->is_ifname));
4515}
4516
4517
4518static void
4519ips_stat_current_to_4_1_21(current, old)
4520	void *current;
4521	ips_stat_4_1_21_t *old;
4522{
4523	ips_stat_t *st = (ips_stat_t *)current;
4524
4525	old->iss_hits = st->iss_hits;
4526	old->iss_miss = st->iss_check_miss;
4527	old->iss_max = st->iss_max;
4528	old->iss_maxref = st->iss_max_ref;
4529	old->iss_tcp = st->iss_proto[IPPROTO_TCP];
4530	old->iss_udp = st->iss_proto[IPPROTO_UDP];
4531	old->iss_icmp = st->iss_proto[IPPROTO_ICMP];
4532	old->iss_nomem = st->iss_nomem;
4533	old->iss_expire = st->iss_expire;
4534	old->iss_fin = st->iss_fin;
4535	old->iss_active = st->iss_active;
4536	old->iss_logged = st->iss_log_ok;
4537	old->iss_logfail = st->iss_log_fail;
4538	old->iss_inuse = st->iss_inuse;
4539	old->iss_wild = st->iss_wild;
4540	old->iss_ticks = st->iss_ticks;
4541	old->iss_bucketfull = st->iss_bucket_full;
4542	old->iss_statesize = st->iss_state_size;
4543	old->iss_statemax = st->iss_state_max;
4544	old->iss_table = st->iss_table;
4545	old->iss_list = st->iss_list;
4546	old->iss_bucketlen = (void *)st->iss_bucketlen;
4547	old->iss_tcptab = st->iss_tcptab;
4548}
4549
4550
4551static void
4552ips_stat_current_to_4_1_0(current, old)
4553	void *current;
4554	ips_stat_4_1_0_t *old;
4555{
4556	ips_stat_t *st = (ips_stat_t *)current;
4557
4558	old->iss_hits = st->iss_hits;
4559	old->iss_miss = st->iss_check_miss;
4560	old->iss_max = st->iss_max;
4561	old->iss_maxref = st->iss_max_ref;
4562	old->iss_tcp = st->iss_proto[IPPROTO_TCP];
4563	old->iss_udp = st->iss_proto[IPPROTO_UDP];
4564	old->iss_icmp = st->iss_proto[IPPROTO_ICMP];
4565	old->iss_nomem = st->iss_nomem;
4566	old->iss_expire = st->iss_expire;
4567	old->iss_fin = st->iss_fin;
4568	old->iss_active = st->iss_active;
4569	old->iss_logged = st->iss_log_ok;
4570	old->iss_logfail = st->iss_log_fail;
4571	old->iss_inuse = st->iss_inuse;
4572	old->iss_wild = st->iss_wild;
4573	old->iss_ticks = st->iss_ticks;
4574	old->iss_bucketfull = st->iss_bucket_full;
4575	old->iss_statesize = st->iss_state_size;
4576	old->iss_statemax = st->iss_state_max;
4577	old->iss_table = st->iss_table;
4578	old->iss_list = st->iss_list;
4579	old->iss_bucketlen = (void *)st->iss_bucketlen;
4580}
4581
4582
4583static void
4584nat_save_current_to_4_1_16(current, old)
4585	void *current;
4586	nat_save_4_1_16_t *old;
4587{
4588	nat_save_t *nats = (nat_save_t *)current;
4589
4590	old->ipn_next = nats->ipn_next;
4591	bcopy(&nats->ipn_nat, &old->ipn_nat, sizeof(old->ipn_nat));
4592	bcopy(&nats->ipn_ipnat, &old->ipn_ipnat, sizeof(old->ipn_ipnat));
4593	frentry_current_to_4_1_16(&nats->ipn_fr, &old->ipn_fr);
4594	old->ipn_dsize = nats->ipn_dsize;
4595	bcopy(nats->ipn_data, old->ipn_data, sizeof(nats->ipn_data));
4596}
4597
4598
4599static void
4600nat_save_current_to_4_1_14(current, old)
4601	void *current;
4602	nat_save_4_1_14_t *old;
4603{
4604	nat_save_t *nats = (nat_save_t *)current;
4605
4606	old->ipn_next = nats->ipn_next;
4607	bcopy(&nats->ipn_nat, &old->ipn_nat, sizeof(old->ipn_nat));
4608	bcopy(&nats->ipn_ipnat, &old->ipn_ipnat, sizeof(old->ipn_ipnat));
4609	frentry_current_to_4_1_0(&nats->ipn_fr, &old->ipn_fr);
4610	old->ipn_dsize = nats->ipn_dsize;
4611	bcopy(nats->ipn_data, old->ipn_data, sizeof(nats->ipn_data));
4612}
4613
4614
4615static void
4616nat_save_current_to_4_1_3(current, old)
4617	void *current;
4618	nat_save_4_1_3_t *old;
4619{
4620	nat_save_t *nats = (nat_save_t *)current;
4621
4622	old->ipn_next = nats->ipn_next;
4623	bcopy(&nats->ipn_nat, &old->ipn_nat, sizeof(old->ipn_nat));
4624	bcopy(&nats->ipn_ipnat, &old->ipn_ipnat, sizeof(old->ipn_ipnat));
4625	frentry_current_to_4_1_0(&nats->ipn_fr, &old->ipn_fr);
4626	old->ipn_dsize = nats->ipn_dsize;
4627	bcopy(nats->ipn_data, old->ipn_data, sizeof(nats->ipn_data));
4628}
4629
4630
4631static void
4632nat_current_to_4_1_25(current, old)
4633	void *current;
4634	nat_4_1_25_t *old;
4635{
4636	nat_t *nat = (nat_t *)current;
4637
4638	old->nat_lock = nat->nat_lock;
4639	old->nat_next = (void *)nat->nat_next;
4640	old->nat_pnext = (void *)nat->nat_pnext;
4641	old->nat_hnext[0] = (void *)nat->nat_hnext[0];
4642	old->nat_hnext[1] = (void *)nat->nat_hnext[1];
4643	old->nat_phnext[0] = (void *)nat->nat_phnext[0];
4644	old->nat_phnext[1] = (void *)nat->nat_phnext[1];
4645	old->nat_hm = nat->nat_hm;
4646	old->nat_data = nat->nat_data;
4647	old->nat_me = (void *)nat->nat_me;
4648	old->nat_state = nat->nat_state;
4649	old->nat_aps = nat->nat_aps;
4650	old->nat_fr = nat->nat_fr;
4651	old->nat_ptr = (void *)nat->nat_ptr;
4652	old->nat_ifps[0] = nat->nat_ifps[0];
4653	old->nat_ifps[1] = nat->nat_ifps[1];
4654	old->nat_sync = nat->nat_sync;
4655	old->nat_tqe = nat->nat_tqe;
4656	old->nat_flags = nat->nat_flags;
4657	old->nat_sumd[0] = nat->nat_sumd[0];
4658	old->nat_sumd[1] = nat->nat_sumd[1];
4659	old->nat_ipsumd = nat->nat_ipsumd;
4660	old->nat_mssclamp = nat->nat_mssclamp;
4661	old->nat_pkts[0] = nat->nat_pkts[0];
4662	old->nat_pkts[1] = nat->nat_pkts[1];
4663	old->nat_bytes[0] = nat->nat_bytes[0];
4664	old->nat_bytes[1] = nat->nat_bytes[1];
4665	old->nat_ref = nat->nat_ref;
4666	old->nat_dir = nat->nat_dir;
4667	old->nat_p = nat->nat_pr[0];
4668	old->nat_use = nat->nat_use;
4669	old->nat_hv[0] = nat->nat_hv[0];
4670	old->nat_hv[1] = nat->nat_hv[1];
4671	old->nat_rev = nat->nat_rev;
4672	old->nat_redir = nat->nat_redir;
4673	bcopy(nat->nat_ifnames[0], old->nat_ifnames[0], LIFNAMSIZ);
4674	bcopy(nat->nat_ifnames[1], old->nat_ifnames[1], LIFNAMSIZ);
4675
4676	if (nat->nat_redir == NAT_REDIRECT) {
4677		old->nat_inip6 = nat->nat_ndst6;
4678		old->nat_outip6 = nat->nat_odst6;
4679		old->nat_oip6 = nat->nat_osrc6;
4680		old->nat_un.nat_unt.ts_sport = nat->nat_ndport;
4681		old->nat_un.nat_unt.ts_dport = nat->nat_odport;
4682	} else {
4683		old->nat_inip6 = nat->nat_osrc6;
4684		old->nat_outip6 = nat->nat_nsrc6;
4685		old->nat_oip6 = nat->nat_odst6;
4686		old->nat_un.nat_unt.ts_sport = nat->nat_osport;
4687		old->nat_un.nat_unt.ts_dport = nat->nat_nsport;
4688	}
4689}
4690
4691
4692static void
4693nat_current_to_4_1_14(current, old)
4694	void *current;
4695	nat_4_1_14_t *old;
4696{
4697	nat_t *nat = (nat_t *)current;
4698
4699	old->nat_lock = nat->nat_lock;
4700	old->nat_next = nat->nat_next;
4701	old->nat_pnext = NULL;
4702	old->nat_hnext[0] = NULL;
4703	old->nat_hnext[1] = NULL;
4704	old->nat_phnext[0] = NULL;
4705	old->nat_phnext[1] = NULL;
4706	old->nat_hm = nat->nat_hm;
4707	old->nat_data = nat->nat_data;
4708	old->nat_me = (void *)nat->nat_me;
4709	old->nat_state = nat->nat_state;
4710	old->nat_aps = nat->nat_aps;
4711	old->nat_fr = nat->nat_fr;
4712	old->nat_ptr = nat->nat_ptr;
4713	old->nat_ifps[0] = nat->nat_ifps[0];
4714	old->nat_ifps[1] = nat->nat_ifps[1];
4715	old->nat_sync = nat->nat_sync;
4716	old->nat_tqe = nat->nat_tqe;
4717	old->nat_flags = nat->nat_flags;
4718	old->nat_sumd[0] = nat->nat_sumd[0];
4719	old->nat_sumd[1] = nat->nat_sumd[1];
4720	old->nat_ipsumd = nat->nat_ipsumd;
4721	old->nat_mssclamp = nat->nat_mssclamp;
4722	old->nat_pkts[0] = nat->nat_pkts[0];
4723	old->nat_pkts[1] = nat->nat_pkts[1];
4724	old->nat_bytes[0] = nat->nat_bytes[0];
4725	old->nat_bytes[1] = nat->nat_bytes[1];
4726	old->nat_ref = nat->nat_ref;
4727	old->nat_dir = nat->nat_dir;
4728	old->nat_p = nat->nat_pr[0];
4729	old->nat_use = nat->nat_use;
4730	old->nat_hv[0] = nat->nat_hv[0];
4731	old->nat_hv[1] = nat->nat_hv[1];
4732	old->nat_rev = nat->nat_rev;
4733	bcopy(nat->nat_ifnames[0], old->nat_ifnames[0], LIFNAMSIZ);
4734	bcopy(nat->nat_ifnames[1], old->nat_ifnames[1], LIFNAMSIZ);
4735
4736	if (nat->nat_redir == NAT_REDIRECT) {
4737		old->nat_inip6 = nat->nat_ndst6;
4738		old->nat_outip6 = nat->nat_odst6;
4739		old->nat_oip6 = nat->nat_osrc6;
4740		old->nat_un.nat_unt.ts_sport = nat->nat_ndport;
4741		old->nat_un.nat_unt.ts_dport = nat->nat_odport;
4742	} else {
4743		old->nat_inip6 = nat->nat_osrc6;
4744		old->nat_outip6 = nat->nat_nsrc6;
4745		old->nat_oip6 = nat->nat_odst6;
4746		old->nat_un.nat_unt.ts_sport = nat->nat_osport;
4747		old->nat_un.nat_unt.ts_dport = nat->nat_nsport;
4748	}
4749}
4750
4751
4752static void
4753nat_current_to_4_1_3(current, old)
4754	void *current;
4755	nat_4_1_3_t *old;
4756{
4757	nat_t *nat = (nat_t *)current;
4758
4759	old->nat_lock = nat->nat_lock;
4760	old->nat_next = nat->nat_next;
4761	old->nat_pnext = NULL;
4762	old->nat_hnext[0] = NULL;
4763	old->nat_hnext[1] = NULL;
4764	old->nat_phnext[0] = NULL;
4765	old->nat_phnext[1] = NULL;
4766	old->nat_hm = nat->nat_hm;
4767	old->nat_data = nat->nat_data;
4768	old->nat_me = (void *)nat->nat_me;
4769	old->nat_state = nat->nat_state;
4770	old->nat_aps = nat->nat_aps;
4771	old->nat_fr = nat->nat_fr;
4772	old->nat_ptr = nat->nat_ptr;
4773	old->nat_ifps[0] = nat->nat_ifps[0];
4774	old->nat_ifps[1] = nat->nat_ifps[1];
4775	old->nat_sync = nat->nat_sync;
4776	old->nat_tqe = nat->nat_tqe;
4777	old->nat_flags = nat->nat_flags;
4778	old->nat_sumd[0] = nat->nat_sumd[0];
4779	old->nat_sumd[1] = nat->nat_sumd[1];
4780	old->nat_ipsumd = nat->nat_ipsumd;
4781	old->nat_mssclamp = nat->nat_mssclamp;
4782	old->nat_pkts[0] = nat->nat_pkts[0];
4783	old->nat_pkts[1] = nat->nat_pkts[1];
4784	old->nat_bytes[0] = nat->nat_bytes[0];
4785	old->nat_bytes[1] = nat->nat_bytes[1];
4786	old->nat_ref = nat->nat_ref;
4787	old->nat_dir = nat->nat_dir;
4788	old->nat_p = nat->nat_pr[0];
4789	old->nat_use = nat->nat_use;
4790	old->nat_hv[0] = nat->nat_hv[0];
4791	old->nat_hv[1] = nat->nat_hv[1];
4792	old->nat_rev = nat->nat_rev;
4793	bcopy(nat->nat_ifnames[0], old->nat_ifnames[0], LIFNAMSIZ);
4794	bcopy(nat->nat_ifnames[1], old->nat_ifnames[1], LIFNAMSIZ);
4795
4796	if (nat->nat_redir == NAT_REDIRECT) {
4797		old->nat_inip6 = nat->nat_ndst6;
4798		old->nat_outip6 = nat->nat_odst6;
4799		old->nat_oip6 = nat->nat_osrc6;
4800		old->nat_un.nat_unt.ts_sport = nat->nat_ndport;
4801		old->nat_un.nat_unt.ts_dport = nat->nat_odport;
4802	} else {
4803		old->nat_inip6 = nat->nat_osrc6;
4804		old->nat_outip6 = nat->nat_nsrc6;
4805		old->nat_oip6 = nat->nat_odst6;
4806		old->nat_un.nat_unt.ts_sport = nat->nat_osport;
4807		old->nat_un.nat_unt.ts_dport = nat->nat_nsport;
4808	}
4809}
4810
4811#endif /* IPFILTER_COMPAT */
4812