xref: /netbsd-src/dist/pf/pf2netbsd (revision 1a30996c875cb15742078df31e3626c8efbe362d)
177ad51d8Smartti#!/bin/sh
277ad51d8Smartti#
3*1a30996cSmartti#   $NetBSD: pf2netbsd,v 1.2 2009/12/02 15:21:37 martti Exp $
477ad51d8Smartti#
577ad51d8Smartti# Copyright (c) 2009 The NetBSD Foundation, Inc.
677ad51d8Smartti# All rights reserved.
777ad51d8Smartti#
877ad51d8Smartti# Redistribution and use in source and binary forms, with or without
977ad51d8Smartti# modification, are permitted provided that the following conditions
1077ad51d8Smartti# are met:
1177ad51d8Smartti# 1. Redistributions of source code must retain the above copyright
1277ad51d8Smartti#    notice, this list of conditions and the following disclaimer.
1377ad51d8Smartti# 2. Redistributions in binary form must reproduce the above copyright
1477ad51d8Smartti#    notice, this list of conditions and the following disclaimer in the
1577ad51d8Smartti#    documentation and/or other materials provided with the distribution.
1677ad51d8Smartti#
1777ad51d8Smartti# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1877ad51d8Smartti# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1977ad51d8Smartti# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2077ad51d8Smartti# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2177ad51d8Smartti# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2277ad51d8Smartti# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2377ad51d8Smartti# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2477ad51d8Smartti# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2577ad51d8Smartti# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2677ad51d8Smartti# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2777ad51d8Smartti# POSSIBILITY OF SUCH DAMAGE.
2877ad51d8Smartti#
2977ad51d8Smartti
3077ad51d8Smarttiusage()
3177ad51d8Smartti{
3277ad51d8Smartti    cat << EOF
3377ad51d8Smartti
3477ad51d8SmarttiUsage: `basename $0` [options] srcdir dstdir
3577ad51d8Smartti
3677ad51d8Smarttiwhere
3777ad51d8Smartti
3877ad51d8Smartti-h      This help
3977ad51d8Smartti-v      Be verbose
4077ad51d8Smartti
4177ad51d8SmarttiExample:
4277ad51d8Smartti
4377ad51d8Smartti`basename $0` /tmp/openbsd-4.2 /tmp/netbsd-4.2
4477ad51d8Smartti
4577ad51d8SmarttiEOF
4677ad51d8Smartti    exit 1
4777ad51d8Smartti}
4877ad51d8Smartti
4977ad51d8Smarttiverbose()
5077ad51d8Smartti{
5177ad51d8Smartti    ${VERBOSE} && echo $*
5277ad51d8Smartti    eval $*
5377ad51d8Smartti}
5477ad51d8Smartti
5577ad51d8Smarttimklist()
5677ad51d8Smartti{
5777ad51d8Smartti    # $1 = filename
5877ad51d8Smartti
5977ad51d8Smartti    if [ -z "$1" ]; then
6077ad51d8Smartti        echo "ERROR: Not enough arguments for mklist!"
6177ad51d8Smartti        exit 1
6277ad51d8Smartti    fi
6377ad51d8Smartti    cat > $1 << EOF
6477ad51d8Smarttietc/pf.conf
6577ad51d8Smarttietc/pf.os
6677ad51d8Smarttilibexec/tftp-proxy/filter.c
6777ad51d8Smarttilibexec/tftp-proxy/filter.h
6877ad51d8Smarttilibexec/tftp-proxy/Makefile
6977ad51d8Smarttilibexec/tftp-proxy/tftp-proxy.8
7077ad51d8Smarttilibexec/tftp-proxy/tftp-proxy.c
7177ad51d8Smarttisbin/pfctl/Makefile
7277ad51d8Smarttisbin/pfctl/parse.y
7377ad51d8Smarttisbin/pfctl/pfctl.8
7477ad51d8Smarttisbin/pfctl/pfctl_altq.c
7577ad51d8Smarttisbin/pfctl/pfctl.c
7677ad51d8Smarttisbin/pfctl/pfctl.h
7777ad51d8Smarttisbin/pfctl/pfctl_optimize.c
7877ad51d8Smarttisbin/pfctl/pfctl_osfp.c
7977ad51d8Smarttisbin/pfctl/pfctl_parser.c
8077ad51d8Smarttisbin/pfctl/pfctl_parser.h
8177ad51d8Smarttisbin/pfctl/pfctl_qstats.c
8277ad51d8Smarttisbin/pfctl/pfctl_radix.c
8377ad51d8Smarttisbin/pfctl/pfctl_table.c
8477ad51d8Smarttisbin/pfctl/pf_print_state.c
8577ad51d8Smarttisbin/pflogd/Makefile
8677ad51d8Smarttisbin/pflogd/pflogd.8
8777ad51d8Smarttisbin/pflogd/pflogd.c
8877ad51d8Smarttisbin/pflogd/pflogd.h
8977ad51d8Smarttisbin/pflogd/privsep.c
9077ad51d8Smarttisbin/pflogd/privsep_fdpass.c
9177ad51d8Smarttishare/man/man4/pf.4
9277ad51d8Smarttishare/man/man4/pflog.4
9377ad51d8Smarttishare/man/man4/pfsync.4
9477ad51d8Smarttishare/man/man5/pf.conf.5
9577ad51d8Smarttishare/man/man5/pf.os.5
9677ad51d8Smarttiusr.sbin/authpf/authpf.8
9777ad51d8Smarttiusr.sbin/authpf/authpf.c
9877ad51d8Smarttiusr.sbin/authpf/Makefile
9977ad51d8Smarttiusr.sbin/authpf/pathnames.h
10077ad51d8Smarttiusr.sbin/ftp-proxy/filter.c
10177ad51d8Smarttiusr.sbin/ftp-proxy/filter.h
10277ad51d8Smarttiusr.sbin/ftp-proxy/ftp-proxy.8
10377ad51d8Smarttiusr.sbin/ftp-proxy/ftp-proxy.c
10477ad51d8Smarttiusr.sbin/ftp-proxy/Makefile
10577ad51d8Smarttisys/net/if.c
10677ad51d8Smarttisys/net/if.h
10777ad51d8Smarttisys/net/if_pflog.c
10877ad51d8Smarttisys/net/if_pflog.h
10977ad51d8Smarttisys/net/if_pfsync.c
11077ad51d8Smarttisys/net/if_pfsync.h
11177ad51d8Smarttisys/net/pf.c
11277ad51d8Smarttisys/net/pf_if.c
11377ad51d8Smarttisys/net/pf_ioctl.c
11477ad51d8Smarttisys/net/pf_norm.c
11577ad51d8Smarttisys/net/pf_osfp.c
11677ad51d8Smarttisys/net/pf_ruleset.c
11777ad51d8Smarttisys/net/pf_table.c
11877ad51d8Smarttisys/net/pfvar.h
11977ad51d8Smarttisys/netinet/tcp_subr.c
12077ad51d8Smarttisys/netinet/tcp_var.h
12177ad51d8SmarttiEOF
12277ad51d8Smartti}
12377ad51d8Smartti
12477ad51d8Smarttiopenbsd2netbsd()
12577ad51d8Smartti{
12677ad51d8Smartti    # $1 = srcdir
12777ad51d8Smartti    # $2 = dstdir
12877ad51d8Smartti
12977ad51d8Smartti    if [ -z "$2" ]; then
13077ad51d8Smartti        echo "ERROR: Not enough arguments for openbsd2netbsd!"
13177ad51d8Smartti        exit 1
13277ad51d8Smartti    fi
13377ad51d8Smartti    if [ -d $2/dist/pf ]; then
13477ad51d8Smartti        echo "ERROR: $2 already exists!"
13577ad51d8Smartti        exit 1
13677ad51d8Smartti    fi
13777ad51d8Smartti    if [ -d "$1/src" ]; then
13877ad51d8Smartti        echo "ERROR: Use $1/src as the srcdir!"
13977ad51d8Smartti        exit 1
14077ad51d8Smartti    fi
14177ad51d8Smartti
14277ad51d8Smartti    cd $1 || exit 1
14377ad51d8Smartti
14477ad51d8Smartti    # Copy from OpenBSD
14577ad51d8Smartti    verbose "mklist /tmp/pf.$$"
14677ad51d8Smartti    verbose "mkdir -p $2"
14777ad51d8Smartti    verbose "tar -c -T /tmp/pf.$$ -f- | tar -x -f- -C $2"
14877ad51d8Smartti
14977ad51d8Smartti    # Some files have different name/location in NetBSD
15077ad51d8Smartti    verbose cd $2
15177ad51d8Smartti    verbose mkdir -p dist/pf sys/dist/pf
15277ad51d8Smartti
15377ad51d8Smartti    verbose cd $2/sys/net
15477ad51d8Smartti    verbose mv if.c if_compat.c
15577ad51d8Smartti    verbose mv if.h if_compat.h
15677ad51d8Smartti    verbose cp pf.c pf_mtag.c
15777ad51d8Smartti    verbose cp pfvar.h pf_mtag.h
15877ad51d8Smartti
15977ad51d8Smartti    verbose cd $2/sys/netinet
16077ad51d8Smartti    verbose mv tcp_subr.c tcp_rndiss.c
16177ad51d8Smartti    verbose mv tcp_var.h tcp_rndiss.h
16277ad51d8Smartti
16377ad51d8Smartti    verbose cd $2
16477ad51d8Smartti    verbose mv etc libexec sbin share usr.sbin dist/pf/
16577ad51d8Smartti
16677ad51d8Smartti    verbose cd $2/sys
16777ad51d8Smartti    verbose mv net netinet dist/pf/
16877ad51d8Smartti
16977ad51d8Smartti    # Remove references to the OpenBSD CVS
17077ad51d8Smartti    find $2 -name CVS | xargs rm -rf
17177ad51d8Smartti
17277ad51d8Smartti#   # Remove the $'s around various CVS keywords
17377ad51d8Smartti#   find $2 -type f | \
17477ad51d8Smartti#   while read f
17577ad51d8Smartti#   do
17677ad51d8Smartti#       sed -e 's/\$\(Id.*\) \$/\1/'        \
17777ad51d8Smartti#           -e 's/\$\(Date.*\) \$/\1/'      \
17877ad51d8Smartti#           -e 's/\$\(Header.*\) \$/\1/'    \
17977ad51d8Smartti#           ${f} > ${f}.fixed
18077ad51d8Smartti#       mv ${f}.fixed ${f}
18177ad51d8Smartti#       echo "Deactivated CVS keywords from ${f}"
18277ad51d8Smartti#   done
18377ad51d8Smartti
18477ad51d8Smartti    # Add the NetBSD keyword
18577ad51d8Smartti    find $2 -type f -name '*.[chly]' | \
18677ad51d8Smartti    grep -v -e if_compat -e tcp_rndiss | \
18777ad51d8Smartti    while read f
18877ad51d8Smartti    do
18977ad51d8Smartti        sed 1q < ${f} | grep -q '\$NetBSD' || (
19077ad51d8Smartti        cat > /tmp/pf2n.$$ <<  EOF
19177ad51d8Smartti/*	\$NetBSD\$	*/
19277ad51d8SmarttiEOF
19377ad51d8Smartti        cat ${f} >> /tmp/pf2n.$$
19477ad51d8Smartti        mv /tmp/pf2n.$$ ${f}
19577ad51d8Smartti        )
19677ad51d8Smartti    done
19777ad51d8Smartti    find $2 -type f -name '*.[0-9]' | \
19877ad51d8Smartti    while read f
19977ad51d8Smartti    do
20077ad51d8Smartti        sed 1q < ${f} | grep -q '\$NetBSD' || (
20177ad51d8Smartti        cat > /tmp/pf2n.$$ <<  EOF
20277ad51d8Smartti.\"	\$NetBSD\$
20377ad51d8SmarttiEOF
20477ad51d8Smartti        cat ${f} >> /tmp/pf2n.$$
20577ad51d8Smartti        mv /tmp/pf2n.$$ ${f}
20677ad51d8Smartti        )
20777ad51d8Smartti    done
20877ad51d8Smartti    find $2 -type f -name 'faq*' -o -name 'queue*' \
20977ad51d8Smartti      -o -name 'ackpri' -o -name 'spamd' | \
21077ad51d8Smartti    while read f
21177ad51d8Smartti    do
21277ad51d8Smartti        sed 1q < ${f} | grep -q '\$NetBSD' || (
21377ad51d8Smartti        cat > /tmp/pf2n.$$ <<  EOF
21477ad51d8Smartti# \$NetBSD\$
21577ad51d8SmarttiEOF
21677ad51d8Smartti        cat ${f} >> /tmp/pf2n.$$
21777ad51d8Smartti        mv /tmp/pf2n.$$ ${f}
21877ad51d8Smartti        )
21977ad51d8Smartti    done
22077ad51d8Smartti    find $2 -type f -name 'Makefile' | \
22177ad51d8Smartti    while read f
22277ad51d8Smartti    do
22377ad51d8Smartti        sed 1q < ${f} | grep -q '\$NetBSD' || (
22477ad51d8Smartti        cat > /tmp/pf2n.$$ <<  EOF
22577ad51d8Smartti#	\$NetBSD\$
22677ad51d8SmarttiEOF
22777ad51d8Smartti        cat ${f} >> /tmp/pf2n.$$
22877ad51d8Smartti        mv /tmp/pf2n.$$ ${f}
22977ad51d8Smartti        )
23077ad51d8Smartti    done
23177ad51d8Smartti}
23277ad51d8Smartti
23377ad51d8Smartti##
23477ad51d8Smartti## MAIN
23577ad51d8Smartti##
23677ad51d8SmarttiVERBOSE=false
23777ad51d8Smartti
23877ad51d8SmarttiARGV=`getopt hv ${*}`
23977ad51d8Smartti[ ${?} != 0 ] && exit 1
24077ad51d8Smarttiset -- ${ARGV}
24177ad51d8Smarttifor i
24277ad51d8Smarttido
24377ad51d8Smartti    case "${i}" in
24477ad51d8Smartti    -h)
24577ad51d8Smartti        usage
24677ad51d8Smartti        shift
24777ad51d8Smartti        ;;
24877ad51d8Smartti    -v)
24977ad51d8Smartti        VERBOSE=true
25077ad51d8Smartti        shift
25177ad51d8Smartti        ;;
25277ad51d8Smartti    --)
25377ad51d8Smartti        shift
25477ad51d8Smartti        ;;
25577ad51d8Smartti    esac
25677ad51d8Smarttidone
25777ad51d8Smartti[ $# -ne 2 ] && usage
25877ad51d8Smartti
25977ad51d8Smarttiopenbsd2netbsd $1 $2
26077ad51d8Smarttirm -f /tmp/pf.$$
26177ad51d8Smarttiecho ""
26277ad51d8Smarttiecho "The sources-to-be-imported are now in $2"
26377ad51d8Smarttiecho ""
264