summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/BSD/kupgrade
blob: 04b257d7ca60f27d5d207f8fb605ca0c02073150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
argv0=`basename $0`
 
os=`uname -s`
rev=`uname -r`
maj=`expr $rev : '\([0-9]*\)\.'`
min=`expr $rev : '[0-9]*\.\([0-9]*\)'`
sub=`expr $rev : '[0-9]*\.[0-9]*\.\([0-9]*\)'`

# try to bomb out fast if anything fails....
set -e

fullrev=`printf '%02d%02d%02d' $maj $min $sub`
dir=`pwd`
karch=`uname -m`
archdir="/sys/arch/$karch"
ipfdir=/sys/netinet
if [ -d /sys/contrib/ipfilter ] ; then
	ipfdir=/sys/contrib/ipfilter/netinet
fi
if [ -d /sys/dist/ipf ] ; then
	ipfdir=/sys/dist/ipf/netinet
fi
confdir="$archdir/conf"
if [ -f /dev/ipnat ] ; then
	major=`ls -l /dev/ipnat | sed -e 's/.* \([0-9]*\),.*/\1/'`
	echo "Major number for IP Filter is $major"
else
	major=x
fi
 
if [ ! -f ip_rules.c -o ! -f ip_rules.h ] ; then
	echo "Trying to build ip_rules.c and ip_rules.h"
	make ip_rules.c
	if [ ! -f ip_rules.c -o ! -f ip_rules.h ] ; then
		echo "Please do a build of ipfilter and then run the following"
		echo "command to build extra files:"
		echo
		echo "make ip_rules.c"
		exit 1
	fi
fi

echo -n "Installing "
for j in auth frag nat proxy scan state sync pool htable lookup rules; do
	for i in ip_$j.[ch]; do
		if [ -f "$i" ] ; then
			echo -n " $i"
			cp $i $ipfdir
			chmod 644 $ipfdir/$i
		fi
	done
done

case $os in
SunOS)
	case `uname -r` in
	5.*)
		filc=ip_fil_solaris.c
		;;
	4.*)
		filc=ip_fil_sunos.c
		;;
	esac
	;;
*BSD)
	filc=ip_fil_`echo $os | tr A-Z a-z`.c
	case $os in
	FreeBSD)
		cp mlfk_ipl.c $ipfdir/
		;;
	*)
		;;
	esac
	;;
esac

if [ -f $ipfdir/$filc ] ; then
	echo -n "$filc -> $ipfdir/$filc "
	cp $filc $ipfdir/$filc
	chmod 644 $ipfdir/$filc
fi
if [ -f $ipfdir/ip_fil.c ] ; then
	echo -n "$filc -> $ipfdir/ip_fil.c "
	cp $filc $ipfdir/ip_fil.c
	chmod 644 $ipfdir/ip_fil.c
fi

for i in ip_fil.h fil.c ip_log.c ip_compat.h ipl.h ip_*_pxy.c; do
	echo -n " $i"
	cp $i $ipfdir
	chmod 644 $ipfdir/$i
done
echo ""
echo -n "Installing into /usr/include/netinet"
for j in auth compat fil frag nat proxy scan state sync pool htable lookup; do
	i=ip_$j.h
	if [ -f "$i" ] ; then
		echo -n " $i"
		cp $i /usr/include/netinet/$i
		chmod 644 /usr/include/netinet/$i
	fi
done
for j in ipl.h; do
	if [ -f "$j" ] ; then
		echo -n " $j"
		cp $j /usr/include/netinet/$j
		chmod 644 /usr/include/netinet/$j
	fi
done
echo

if [ -f /sys/netinet/ip_fil_compat.h ] ; then
	echo "Linking /sys/netinet/ip_compat.h to /sys/netinet/ip_fil_compat.h"
	rm /sys/netinet/ip_fil_compat.h
	ln -s /sys/netinet/ip_compat.h /sys/netinet/ip_fil_compat.h
fi

if [ $major != x ] ; then
	if [ ! -e /dev/ipsync ] ; then
		echo "Creating /dev/ipsync"
		mknod /dev/ipsync c $major 4
	fi

	if [ ! -e /dev/ipsync ] ; then
		echo "Creating /dev/ipscan"
		mknod /dev/ipsync c $major 5
	fi

	if [ ! -e /dev/iplookup ] ; then
		echo "Creating /dev/iplookup"
		mknod /dev/iplookup c $major 6
	fi
fi

set +e
os=`uname -s`
if [ $os = FreeBSD -a -f /sys/conf/files ] ; then
	cd /sys/conf
	if [ -f options ] ; then
		if [ ! -f options.preipf4 ] ; then
			mv options options.preipf4
			cp -p options.preipf4 options
		fi
		for i in SCAN SYNC LOOKUP COMPILED; do
			grep IPFILTER_$i options >/dev/null 2>&1
			if [ $? -ne 0 ] ; then
				echo >> options
				echo "# extra option for IP Filter" >> options
				echo "IPFILTER_$i	opt_ipfilter.h" >> options
			fi
		done
	fi
	if [ ! -f files.preipf4 ] ; then
		mv files files.preipf4
		cp -p files.preipf4 files
	fi
	for i in htable pool lookup; do
		grep ip_$i.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo "contrib/ipfilter/netinet/ip_$i.c	optional ipfilter inet ipfilter_lookup" >> files
		fi
	done
	grep ip_sync.c files >/dev/null 2>&1
	if [ $? -ne 0 ] ; then
		echo 'contrib/ipfilter/netinet/ip_sync.c	optional ipfilter inet ipfilter_sync' >> files
	fi
	grep ip_scan.c files >/dev/null 2>&1
	if [ $? -ne 0 ] ; then
		echo 'contrib/ipfilter/netinet/ip_scan.c	optional ipfilter inet ipfilter_scan' >> files
	fi
	grep ip_rules.c files >/dev/null 2>&1
	if [ $? -ne 0 ] ; then
		echo 'contrib/ipfilter/netinet/ip_rules.c	optional ipfilter inet ipfilter_compiled' >> files
	fi
fi
if [ $os = NetBSD -a -f /sys/conf/files ] ; then
	cd /sys/conf
	if [ ! -f files.preipf4 ] ; then
		mv files files.preipf4
		cp -p files.preipf4 files
	fi
	if [ $fullrev -ge 010600 -a $fullrev -lt 020000 ] ; then
		for i in htable pool lookup; do
			grep ip_$i.c files >/dev/null 2>&1
			if [ $? -ne 0 ] ; then
				echo "file	netinet/ip_$i.c	ipfilter & ipfilter_lookup" >> files
			fi
		done
		grep ip_sync.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_sync.c	ipfilter & ipfilter_sync' >> files
		fi
		grep ip_scan.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_scan.c	ipfilter & ipfilter_scan' >> files
		fi
		grep ip_rules.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_rules.c	ipfilter & ipfilter_compiled' >> files
		fi
	fi
fi
if [ $os = OpenBSD -a -f /sys/conf/files ] ; then
	cd /sys/conf
	if [ ! -f files.preipf4 ] ; then
		mv files files.preipf4
		cp -p files.preipf4 files
	fi
	if [ $fullrev -ge 030400 ] ; then
		for i in htable pool lookup; do
			grep ip_$i.c files >/dev/null 2>&1
			if [ $? -ne 0 ] ; then
				echo "file	netinet/ip_$i.c	ipfilter & ipfilter_lookup" >> files
			fi
		done
		grep ip_sync.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_sync.c	ipfilter & ipfilter_sync' >> files
		fi
		grep ip_scan.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_scan.c	ipfilter & ipfilter_scan' >> files
		fi
		grep ip_rules.c files >/dev/null 2>&1
		if [ $? -ne 0 ] ; then
			echo 'file	netinet/ip_rules.c	ipfilter & ipfilter_compiled' >> files
		fi
	fi
fi

if [ -f /usr/src/sys/modules/ipfilter/Makefile -a \
   ! -f /usr/src/sys/modules/ipfilter/Makefile.orig ] ; then
cat | (cd /usr/src/sys/modules/ipfilter; patch) <<__EOF__
*** Makefile.orig	Mon Mar 28 09:10:11 2005
--- Makefile	Mon Mar 28 09:12:51 2005
***************
*** 5,13 ****
  KMOD=	ipl
  SRCS=	mlfk_ipl.c ip_nat.c ip_frag.c ip_state.c ip_proxy.c ip_auth.c \\
! 	ip_log.c ip_fil.c fil.c
  
  .if !defined(NOINET6)
  CFLAGS+= -DUSE_INET6
  .endif
  CFLAGS+=  -I$${.CURDIR}/../../contrib/ipfilter
! CFLAGS+= -DIPFILTER=1 -DIPFILTER_LKM -DIPFILTER_LOG -DPFIL_HOOKS
--- 5,15 ----
  KMOD=	ipl
  SRCS=	mlfk_ipl.c ip_nat.c ip_frag.c ip_state.c ip_proxy.c ip_auth.c \\
! 	ip_log.c ip_fil.c fil.c ip_lookup.c ip_pool.c ip_htable.c \\
! 	ip_sync.c ip_scan.c ip_rules.c
  
  .if !defined(NOINET6)
  CFLAGS+= -DUSE_INET6
  .endif
  CFLAGS+=  -I$${.CURDIR}/../../contrib/ipfilter
! CFLAGS+= -DIPFILTER=1 -DIPFILTER_LKM -DIPFILTER_LOG -DPFIL_HOOKS \\
! 	-DIPFILTER_LOOKUP -DIPFILTER_COMPILED
__EOF__
fi
exit 0
OpenPOWER on IntegriCloud