Home | History | Annotate | Line # | Download | only in pf
      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 
     30 usage()
     31 {
     32     cat << EOF
     33 
     34 Usage: `basename $0` [options] srcdir dstdir
     35 
     36 where
     37 
     38 -h      This help
     39 -v      Be verbose
     40 
     41 Example:
     42 
     43 `basename $0` /tmp/openbsd-4.2 /tmp/netbsd-4.2
     44 
     45 EOF
     46     exit 1
     47 }
     48 
     49 verbose()
     50 {
     51     ${VERBOSE} && echo $*
     52     eval $*
     53 }
     54 
     55 mklist()
     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
     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
    121 EOF
    122 }
    123 
    124 openbsd2netbsd()
    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\$	*/
    192 EOF
    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\$
    203 EOF
    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\$
    215 EOF
    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\$
    226 EOF
    227         cat ${f} >> /tmp/pf2n.$$
    228         mv /tmp/pf2n.$$ ${f}
    229         )
    230     done
    231 }
    232 
    233 ##
    234 ## MAIN
    235 ##
    236 VERBOSE=false
    237 
    238 ARGV=`getopt hv ${*}`
    239 [ ${?} != 0 ] && exit 1
    240 set -- ${ARGV}
    241 for i
    242 do
    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
    256 done
    257 [ $# -ne 2 ] && usage
    258 
    259 openbsd2netbsd $1 $2
    260 rm -f /tmp/pf.$$
    261 echo ""
    262 echo "The sources-to-be-imported are now in $2"
    263 echo ""
    264