Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / pf / pf2netbsd
blobfd297a82084f1f5da291c399ec242174d4893f9f
1 #!/bin/sh
3 # $NetBSD: pf2netbsd,v 1.1 2009/12/01 06:27:57 martti Exp $
5 # Copyright (c) 2009 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
30 usage()
32 cat << EOF
34 Usage: `basename $0` [options] srcdir dstdir
36 where
38 -h This help
39 -v Be verbose
41 Example:
43 `basename $0` /tmp/openbsd-4.2 /tmp/netbsd-4.2
45 EOF
46 exit 1
49 verbose()
51 ${VERBOSE} && echo $*
52 eval $*
55 mklist()
57 # $1 = filename
59 if [ -z "$1" ]; then
60 echo "ERROR: Not enough arguments for mklist!"
61 exit 1
63 cat > $1 << EOF
64 etc/pf.conf
65 etc/pf.os
66 libexec/tftp-proxy/filter.c
67 libexec/tftp-proxy/filter.h
68 libexec/tftp-proxy/Makefile
69 libexec/tftp-proxy/tftp-proxy.8
70 libexec/tftp-proxy/tftp-proxy.c
71 sbin/pfctl/Makefile
72 sbin/pfctl/parse.y
73 sbin/pfctl/pfctl.8
74 sbin/pfctl/pfctl_altq.c
75 sbin/pfctl/pfctl.c
76 sbin/pfctl/pfctl.h
77 sbin/pfctl/pfctl_optimize.c
78 sbin/pfctl/pfctl_osfp.c
79 sbin/pfctl/pfctl_parser.c
80 sbin/pfctl/pfctl_parser.h
81 sbin/pfctl/pfctl_qstats.c
82 sbin/pfctl/pfctl_radix.c
83 sbin/pfctl/pfctl_table.c
84 sbin/pfctl/pf_print_state.c
85 sbin/pflogd/Makefile
86 sbin/pflogd/pflogd.8
87 sbin/pflogd/pflogd.c
88 sbin/pflogd/pflogd.h
89 sbin/pflogd/privsep.c
90 sbin/pflogd/privsep_fdpass.c
91 share/man/man4/pf.4
92 share/man/man4/pflog.4
93 share/man/man4/pfsync.4
94 share/man/man5/pf.conf.5
95 share/man/man5/pf.os.5
96 usr.sbin/authpf/authpf.8
97 usr.sbin/authpf/authpf.c
98 usr.sbin/authpf/Makefile
99 usr.sbin/authpf/pathnames.h
100 usr.sbin/ftp-proxy/filter.c
101 usr.sbin/ftp-proxy/filter.h
102 usr.sbin/ftp-proxy/ftp-proxy.8
103 usr.sbin/ftp-proxy/ftp-proxy.c
104 usr.sbin/ftp-proxy/Makefile
105 sys/net/if.c
106 sys/net/if.h
107 sys/net/if_pflog.c
108 sys/net/if_pflog.h
109 sys/net/if_pfsync.c
110 sys/net/if_pfsync.h
111 sys/net/pf.c
112 sys/net/pf_if.c
113 sys/net/pf_ioctl.c
114 sys/net/pf_norm.c
115 sys/net/pf_osfp.c
116 sys/net/pf_ruleset.c
117 sys/net/pf_table.c
118 sys/net/pfvar.h
119 sys/netinet/tcp_subr.c
120 sys/netinet/tcp_var.h
124 openbsd2netbsd()
126 # $1 = srcdir
127 # $2 = dstdir
129 if [ -z "$2" ]; then
130 echo "ERROR: Not enough arguments for openbsd2netbsd!"
131 exit 1
133 if [ -d $2/dist/pf ]; then
134 echo "ERROR: $2 already exists!"
135 exit 1
137 if [ -d "$1/src" ]; then
138 echo "ERROR: Use $1/src as the srcdir!"
139 exit 1
142 cd $1 || exit 1
144 # Copy from OpenBSD
145 verbose "mklist /tmp/pf.$$"
146 verbose "mkdir -p $2"
147 verbose "tar -c -T /tmp/pf.$$ -f- | tar -x -f- -C $2"
149 # Some files have different name/location in NetBSD
150 verbose cd $2
151 verbose mkdir -p dist/pf sys/dist/pf
153 verbose cd $2/sys/net
154 verbose mv if.c if_compat.c
155 verbose mv if.h if_compat.h
156 verbose cp pf.c pf_mtag.c
157 verbose cp pfvar.h pf_mtag.h
159 verbose cd $2/sys/netinet
160 verbose mv tcp_subr.c tcp_rndiss.c
161 verbose mv tcp_var.h tcp_rndiss.h
163 verbose cd $2
164 verbose mv etc libexec sbin share usr.sbin dist/pf/
166 verbose cd $2/sys
167 verbose mv net netinet dist/pf/
169 # Remove references to the OpenBSD CVS
170 find $2 -name CVS | xargs rm -rf
172 # # Remove the $'s around various CVS keywords
173 # find $2 -type f | \
174 # while read f
175 # do
176 # sed -e 's/\$\(Id.*\) \$/\1/' \
177 # -e 's/\$\(Date.*\) \$/\1/' \
178 # -e 's/\$\(Header.*\) \$/\1/' \
179 # ${f} > ${f}.fixed
180 # mv ${f}.fixed ${f}
181 # echo "Deactivated CVS keywords from ${f}"
182 # done
184 # Add the NetBSD keyword
185 find $2 -type f -name '*.[chly]' | \
186 grep -v -e if_compat -e tcp_rndiss | \
187 while read f
189 sed 1q < ${f} | grep -q '\$NetBSD' || (
190 cat > /tmp/pf2n.$$ << EOF
191 /* \$NetBSD\$ */
193 cat ${f} >> /tmp/pf2n.$$
194 mv /tmp/pf2n.$$ ${f}
196 done
197 find $2 -type f -name '*.[0-9]' | \
198 while read f
200 sed 1q < ${f} | grep -q '\$NetBSD' || (
201 cat > /tmp/pf2n.$$ << EOF
202 .\" \$NetBSD\$
204 cat ${f} >> /tmp/pf2n.$$
205 mv /tmp/pf2n.$$ ${f}
207 done
208 find $2 -type f -name 'faq*' -o -name 'queue*' \
209 -o -name 'ackpri' -o -name 'spamd' | \
210 while read f
212 sed 1q < ${f} | grep -q '\$NetBSD' || (
213 cat > /tmp/pf2n.$$ << EOF
214 # \$NetBSD\$
216 cat ${f} >> /tmp/pf2n.$$
217 mv /tmp/pf2n.$$ ${f}
219 done
220 find $2 -type f -name 'Makefile' | \
221 while read f
223 sed 1q < ${f} | grep -q '\$NetBSD' || (
224 cat > /tmp/pf2n.$$ << EOF
225 # \$NetBSD\$
227 cat ${f} >> /tmp/pf2n.$$
228 mv /tmp/pf2n.$$ ${f}
230 done
234 ## MAIN
236 VERBOSE=false
238 ARGV=`getopt hv ${*}`
239 [ ${?} != 0 ] && exit 1
240 set -- ${ARGV}
241 for i
243 case "${i}" in
245 usage
246 shift
249 VERBOSE=true
250 shift
253 shift
255 esac
256 done
257 [ $# -ne 2 ] && usage
259 openbsd2netbsd $1 $2
260 rm -f /tmp/pf.$$
261 echo ""
262 echo "The sources-to-be-imported are now in $2"
263 echo ""