pf2netbsd revision 1.1
1#!/bin/sh 2# 3# $NetBSD: pf2netbsd,v 1.1 2009/12/01 06:27:57 martti Exp $ 4# 5# Copyright (c) 2009 The NetBSD Foundation, Inc. 6# All rights reserved. 7# 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. 16# 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. 28# 29 30usage() 31{ 32 cat << EOF 33 34Usage: `basename $0` [options] srcdir dstdir 35 36where 37 38-h This help 39-v Be verbose 40 41Example: 42 43`basename $0` /tmp/openbsd-4.2 /tmp/netbsd-4.2 44 45EOF 46 exit 1 47} 48 49verbose() 50{ 51 ${VERBOSE} && echo $* 52 eval $* 53} 54 55mklist() 56{ 57 # $1 = filename 58 59 if [ -z "$1" ]; then 60 echo "ERROR: Not enough arguments for mklist!" 61 exit 1 62 fi 63 cat > $1 << EOF 64etc/pf.conf 65etc/pf.os 66libexec/tftp-proxy/filter.c 67libexec/tftp-proxy/filter.h 68libexec/tftp-proxy/Makefile 69libexec/tftp-proxy/tftp-proxy.8 70libexec/tftp-proxy/tftp-proxy.c 71sbin/pfctl/Makefile 72sbin/pfctl/parse.y 73sbin/pfctl/pfctl.8 74sbin/pfctl/pfctl_altq.c 75sbin/pfctl/pfctl.c 76sbin/pfctl/pfctl.h 77sbin/pfctl/pfctl_optimize.c 78sbin/pfctl/pfctl_osfp.c 79sbin/pfctl/pfctl_parser.c 80sbin/pfctl/pfctl_parser.h 81sbin/pfctl/pfctl_qstats.c 82sbin/pfctl/pfctl_radix.c 83sbin/pfctl/pfctl_table.c 84sbin/pfctl/pf_print_state.c 85sbin/pflogd/Makefile 86sbin/pflogd/pflogd.8 87sbin/pflogd/pflogd.c 88sbin/pflogd/pflogd.h 89sbin/pflogd/privsep.c 90sbin/pflogd/privsep_fdpass.c 91share/man/man4/pf.4 92share/man/man4/pflog.4 93share/man/man4/pfsync.4 94share/man/man5/pf.conf.5 95share/man/man5/pf.os.5 96share/pf/ackpri 97share/pf/faq-example1 98share/pf/faq-example2 99share/pf/faq-example3 100share/pf/Makefile 101share/pf/queue1 102share/pf/queue2 103share/pf/queue3 104share/pf/queue4 105share/pf/spamd 106usr.sbin/authpf/authpf.8 107usr.sbin/authpf/authpf.c 108usr.sbin/authpf/Makefile 109usr.sbin/authpf/pathnames.h 110usr.sbin/ftp-proxy/filter.c 111usr.sbin/ftp-proxy/filter.h 112usr.sbin/ftp-proxy/ftp-proxy.8 113usr.sbin/ftp-proxy/ftp-proxy.c 114usr.sbin/ftp-proxy/Makefile 115sys/net/if.c 116sys/net/if.h 117sys/net/if_pflog.c 118sys/net/if_pflog.h 119sys/net/if_pfsync.c 120sys/net/if_pfsync.h 121sys/net/pf.c 122sys/net/pf_if.c 123sys/net/pf_ioctl.c 124sys/net/pf_norm.c 125sys/net/pf_osfp.c 126sys/net/pf_ruleset.c 127sys/net/pf_table.c 128sys/net/pfvar.h 129sys/netinet/tcp_subr.c 130sys/netinet/tcp_var.h 131EOF 132} 133 134openbsd2netbsd() 135{ 136 # $1 = srcdir 137 # $2 = dstdir 138 139 if [ -z "$2" ]; then 140 echo "ERROR: Not enough arguments for openbsd2netbsd!" 141 exit 1 142 fi 143 if [ -d $2/dist/pf ]; then 144 echo "ERROR: $2 already exists!" 145 exit 1 146 fi 147 if [ -d "$1/src" ]; then 148 echo "ERROR: Use $1/src as the srcdir!" 149 exit 1 150 fi 151 152 cd $1 || exit 1 153 154 # Copy from OpenBSD 155 verbose "mklist /tmp/pf.$$" 156 verbose "mkdir -p $2" 157 verbose "tar -c -T /tmp/pf.$$ -f- | tar -x -f- -C $2" 158 159 # Some files have different name/location in NetBSD 160 verbose cd $2 161 verbose mkdir -p dist/pf sys/dist/pf 162 163 verbose cd $2/sys/net 164 verbose mv if.c if_compat.c 165 verbose mv if.h if_compat.h 166 verbose cp pf.c pf_mtag.c 167 verbose cp pfvar.h pf_mtag.h 168 169 verbose cd $2/sys/netinet 170 verbose mv tcp_subr.c tcp_rndiss.c 171 verbose mv tcp_var.h tcp_rndiss.h 172 173 verbose cd $2 174 verbose mv etc libexec sbin share usr.sbin dist/pf/ 175 176 verbose cd $2/sys 177 verbose mv net netinet dist/pf/ 178 179 # Remove references to the OpenBSD CVS 180 find $2 -name CVS | xargs rm -rf 181 182# # Remove the $'s around various CVS keywords 183# find $2 -type f | \ 184# while read f 185# do 186# sed -e 's/\$\(Id.*\) \$/\1/' \ 187# -e 's/\$\(Date.*\) \$/\1/' \ 188# -e 's/\$\(Header.*\) \$/\1/' \ 189# ${f} > ${f}.fixed 190# mv ${f}.fixed ${f} 191# echo "Deactivated CVS keywords from ${f}" 192# done 193 194 # Add the NetBSD keyword 195 find $2 -type f -name '*.[chly]' | \ 196 grep -v -e if_compat -e tcp_rndiss | \ 197 while read f 198 do 199 sed 1q < ${f} | grep -q '\$NetBSD' || ( 200 cat > /tmp/pf2n.$$ << EOF 201/* \$NetBSD\$ */ 202EOF 203 cat ${f} >> /tmp/pf2n.$$ 204 mv /tmp/pf2n.$$ ${f} 205 ) 206 done 207 find $2 -type f -name '*.[0-9]' | \ 208 while read f 209 do 210 sed 1q < ${f} | grep -q '\$NetBSD' || ( 211 cat > /tmp/pf2n.$$ << EOF 212.\" \$NetBSD\$ 213EOF 214 cat ${f} >> /tmp/pf2n.$$ 215 mv /tmp/pf2n.$$ ${f} 216 ) 217 done 218 find $2 -type f -name 'faq*' -o -name 'queue*' \ 219 -o -name 'ackpri' -o -name 'spamd' | \ 220 while read f 221 do 222 sed 1q < ${f} | grep -q '\$NetBSD' || ( 223 cat > /tmp/pf2n.$$ << EOF 224# \$NetBSD\$ 225EOF 226 cat ${f} >> /tmp/pf2n.$$ 227 mv /tmp/pf2n.$$ ${f} 228 ) 229 done 230 find $2 -type f -name 'Makefile' | \ 231 while read f 232 do 233 sed 1q < ${f} | grep -q '\$NetBSD' || ( 234 cat > /tmp/pf2n.$$ << EOF 235# \$NetBSD\$ 236EOF 237 cat ${f} >> /tmp/pf2n.$$ 238 mv /tmp/pf2n.$$ ${f} 239 ) 240 done 241} 242 243## 244## MAIN 245## 246VERBOSE=false 247 248ARGV=`getopt hv ${*}` 249[ ${?} != 0 ] && exit 1 250set -- ${ARGV} 251for i 252do 253 case "${i}" in 254 -h) 255 usage 256 shift 257 ;; 258 -v) 259 VERBOSE=true 260 shift 261 ;; 262 --) 263 shift 264 ;; 265 esac 266done 267[ $# -ne 2 ] && usage 268 269openbsd2netbsd $1 $2 270rm -f /tmp/pf.$$ 271echo "" 272echo "The sources-to-be-imported are now in $2" 273echo "" 274