1#!/bin/sh 2# 3# $NetBSD: pf2netbsd,v 1.2 2009/12/02 15:21:37 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 96usr.sbin/authpf/authpf.8 97usr.sbin/authpf/authpf.c 98usr.sbin/authpf/Makefile 99usr.sbin/authpf/pathnames.h 100usr.sbin/ftp-proxy/filter.c 101usr.sbin/ftp-proxy/filter.h 102usr.sbin/ftp-proxy/ftp-proxy.8 103usr.sbin/ftp-proxy/ftp-proxy.c 104usr.sbin/ftp-proxy/Makefile 105sys/net/if.c 106sys/net/if.h 107sys/net/if_pflog.c 108sys/net/if_pflog.h 109sys/net/if_pfsync.c 110sys/net/if_pfsync.h 111sys/net/pf.c 112sys/net/pf_if.c 113sys/net/pf_ioctl.c 114sys/net/pf_norm.c 115sys/net/pf_osfp.c 116sys/net/pf_ruleset.c 117sys/net/pf_table.c 118sys/net/pfvar.h 119sys/netinet/tcp_subr.c 120sys/netinet/tcp_var.h 121EOF 122} 123 124openbsd2netbsd() 125{ 126 # $1 = srcdir 127 # $2 = dstdir 128 129 if [ -z "$2" ]; then 130 echo "ERROR: Not enough arguments for openbsd2netbsd!" 131 exit 1 132 fi 133 if [ -d $2/dist/pf ]; then 134 echo "ERROR: $2 already exists!" 135 exit 1 136 fi 137 if [ -d "$1/src" ]; then 138 echo "ERROR: Use $1/src as the srcdir!" 139 exit 1 140 fi 141 142 cd $1 || exit 1 143 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" 148 149 # Some files have different name/location in NetBSD 150 verbose cd $2 151 verbose mkdir -p dist/pf sys/dist/pf 152 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 158 159 verbose cd $2/sys/netinet 160 verbose mv tcp_subr.c tcp_rndiss.c 161 verbose mv tcp_var.h tcp_rndiss.h 162 163 verbose cd $2 164 verbose mv etc libexec sbin share usr.sbin dist/pf/ 165 166 verbose cd $2/sys 167 verbose mv net netinet dist/pf/ 168 169 # Remove references to the OpenBSD CVS 170 find $2 -name CVS | xargs rm -rf 171 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 183 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 188 do 189 sed 1q < ${f} | grep -q '\$NetBSD' || ( 190 cat > /tmp/pf2n.$$ << EOF 191/* \$NetBSD\$ */ 192EOF 193 cat ${f} >> /tmp/pf2n.$$ 194 mv /tmp/pf2n.$$ ${f} 195 ) 196 done 197 find $2 -type f -name '*.[0-9]' | \ 198 while read f 199 do 200 sed 1q < ${f} | grep -q '\$NetBSD' || ( 201 cat > /tmp/pf2n.$$ << EOF 202.\" \$NetBSD\$ 203EOF 204 cat ${f} >> /tmp/pf2n.$$ 205 mv /tmp/pf2n.$$ ${f} 206 ) 207 done 208 find $2 -type f -name 'faq*' -o -name 'queue*' \ 209 -o -name 'ackpri' -o -name 'spamd' | \ 210 while read f 211 do 212 sed 1q < ${f} | grep -q '\$NetBSD' || ( 213 cat > /tmp/pf2n.$$ << EOF 214# \$NetBSD\$ 215EOF 216 cat ${f} >> /tmp/pf2n.$$ 217 mv /tmp/pf2n.$$ ${f} 218 ) 219 done 220 find $2 -type f -name 'Makefile' | \ 221 while read f 222 do 223 sed 1q < ${f} | grep -q '\$NetBSD' || ( 224 cat > /tmp/pf2n.$$ << EOF 225# \$NetBSD\$ 226EOF 227 cat ${f} >> /tmp/pf2n.$$ 228 mv /tmp/pf2n.$$ ${f} 229 ) 230 done 231} 232 233## 234## MAIN 235## 236VERBOSE=false 237 238ARGV=`getopt hv ${*}` 239[ ${?} != 0 ] && exit 1 240set -- ${ARGV} 241for i 242do 243 case "${i}" in 244 -h) 245 usage 246 shift 247 ;; 248 -v) 249 VERBOSE=true 250 shift 251 ;; 252 --) 253 shift 254 ;; 255 esac 256done 257[ $# -ne 2 ] && usage 258 259openbsd2netbsd $1 $2 260rm -f /tmp/pf.$$ 261echo "" 262echo "The sources-to-be-imported are now in $2" 263echo "" 264