1 # Copyright (C) 2006 OpenWrt.org
3 function portstr
(type
, str
) {
5 if (insmod_mport
!= 1) {
6 print "insmod ipt_multiport >&- 2>&-"
9 if (type ==
"src") return " -m multiport --sports " str
10 else return " -m multiport --dports " str
13 function str2ipt
(str
) {
16 if (_l
["src"] != "") _cmd = _cmd
" -s " _l
["src"]
17 if (_l
["dest"] != "") _cmd = _cmd
" -d " _l
["dest"]
18 if (_l
["proto"] != "") {
19 _cmd = _cmd
" -p " _l
["proto"]
21 # scripts need to check for proto="" and emit two rules in that case
22 if ((_l
["proto"] ==
"") || (_l
["proto"] ==
"tcp") || (_l
["proto"] ==
"udp")) {
23 if (_l
["sport"] != "") _cmd = _cmd portstr
("src", _l
["sport"])
24 if (_l
["dport"] != "") _cmd = _cmd portstr
("dest", _l
["dport"])
26 if (_l
["layer7"] != "") {
28 print "insmod ipt_layer7 >&- 2>&-"
31 _cmd = _cmd
" -m layer7 --l7proto " _l
["layer7"]
36 function str2data
(str
) {
38 _n =
split(str
, _o
, "[\t ]")
39 for (_i =
1; _i
<= _n
; _i
++) {
40 _n2 =
split(_o
[_i
], _c
, "=")
41 if (_n2 ==
2) _l
[_c
[1]] = _c
[2]
45 function bitcount
(c
) {
46 c=and
(rshift
(c
, 1),0x55555555)+and
(c
,0x55555555)
47 c=and
(rshift
(c
, 2),0x33333333)+and
(c
,0x33333333)
48 c=and
(rshift
(c
, 4),0x0f0f0f0f)+and
(c
,0x0f0f0f0f)
49 c=and
(rshift
(c
, 8),0x00ff00ff)+and
(c
,0x00ff00ff)
50 c=and
(rshift
(c
,16),0x0000ffff)+and
(c
,0x0000ffff)
54 function validate_netmask
(nm
) {
55 return and
(-nm
,compl
(nm
))
59 for (ret=
0,n=
split(ip
,a
,"\."),x=
1;x
<=n
;x
++) ret=or
(lshift
(ret
,8),a
[x
])
63 function int2ip
(ip
,ret
,x
) {
66 for(;x
<3;ret=and
(ip
,255)"."ret
,ip=rshift
(ip
,8),x
++);
This page took 0.045051 seconds and 5 git commands to generate.