Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
c37d77bc
Commit
c37d77bc
authored
Apr 05, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inc: refactor code and improve error messages of parse_filter_line()
parent
f21708cb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
106 deletions
+112
-106
filter_log.inc
src/etc/inc/filter_log.inc
+112
-106
No files found.
src/etc/inc/filter_log.inc
View file @
c37d77bc
...
@@ -121,18 +121,18 @@ function in_arrayi($needle, $haystack) {
...
@@ -121,18 +121,18 @@ function in_arrayi($needle, $haystack) {
return
in_array
(
strtolower
(
$needle
),
array_map
(
'strtolower'
,
$haystack
));
return
in_array
(
strtolower
(
$needle
),
array_map
(
'strtolower'
,
$haystack
));
}
}
function
parse_filter_line
(
$line
)
{
function
parse_filter_line
(
$line
)
global
$config
,
$g
;
{
$flent
=
array
();
$flent
=
array
();
$log_split
=
""
;
$log_split
=
''
;
if
(
!
preg_match
(
"/(.*)\s(.*)\sfilterlog:\s(.*)$/"
,
$line
,
$log_split
))
if
(
!
preg_match
(
'/(.*)\s(.*)\sfilterlog:\s(.*)$/'
,
$line
,
$log_split
))
{
return
""
;
return
''
;
}
list
(
$all
,
$flent
[
'time'
],
$host
,
$rule
)
=
$log_split
;
list
(
$all
,
$flent
[
'time'
],
$host
,
$rule
)
=
$log_split
;
$rule_data
=
explode
(
","
,
$rule
);
$rule_data
=
explode
(
','
,
$rule
);
$field
=
0
;
$field
=
0
;
$flent
[
'rulenum'
]
=
$rule_data
[
$field
++
];
$flent
[
'rulenum'
]
=
$rule_data
[
$field
++
];
...
@@ -146,8 +146,15 @@ function parse_filter_line($line) {
...
@@ -146,8 +146,15 @@ function parse_filter_line($line) {
$flent
[
'direction'
]
=
$rule_data
[
$field
++
];
$flent
[
'direction'
]
=
$rule_data
[
$field
++
];
$flent
[
'version'
]
=
$rule_data
[
$field
++
];
$flent
[
'version'
]
=
$rule_data
[
$field
++
];
if
(
$flent
[
'version'
]
!=
'4'
&&
$flent
[
'version'
]
!=
'6'
)
{
log_error
(
sprintf
(
gettext
(
"There was a error parsing rule number: %s -- not IPv4 or IPv6 (`%s')"
),
$flent
[
'rulenum'
],
$rule
));
return
''
;
}
if
(
$flent
[
'version'
]
==
'4'
||
$flent
[
'version'
]
==
'6'
)
{
if
(
$flent
[
'version'
]
==
'4'
)
{
if
(
$flent
[
'version'
]
==
'4'
)
{
$flent
[
'tos'
]
=
$rule_data
[
$field
++
];
$flent
[
'tos'
]
=
$rule_data
[
$field
++
];
$flent
[
'ecn'
]
=
$rule_data
[
$field
++
];
$flent
[
'ecn'
]
=
$rule_data
[
$field
++
];
...
@@ -192,36 +199,36 @@ function parse_filter_line($line) {
...
@@ -192,36 +199,36 @@ function parse_filter_line($line) {
$flent
[
'icmp_type'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_type'
]
=
$rule_data
[
$field
++
];
switch
(
$flent
[
'icmp_type'
])
{
switch
(
$flent
[
'icmp_type'
])
{
case
"request"
:
case
'request'
:
case
"reply"
:
case
'reply'
:
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"unreachproto"
:
case
'unreachproto'
:
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_protoid'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_protoid'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"unreachport"
:
case
'unreachport'
:
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_protoid'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_protoid'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_port'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_port'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"unreach"
:
case
'unreach'
:
case
"timexceed"
:
case
'timexceed'
:
case
"paramprob"
:
case
'paramprob'
:
case
"redirect"
:
case
'redirect'
:
case
"maskreply"
:
case
'maskreply'
:
$flent
[
'icmp_descr'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_descr'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"needfrag"
:
case
'needfrag'
:
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_dstip'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_mtu'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_mtu'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"tstamp"
:
case
'tstamp'
:
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
break
;
break
;
case
"tstampreply"
:
case
'tstampreply'
:
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_id'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_seq'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_otime'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_otime'
]
=
$rule_data
[
$field
++
];
...
@@ -232,7 +239,6 @@ function parse_filter_line($line) {
...
@@ -232,7 +239,6 @@ function parse_filter_line($line) {
$flent
[
'icmp_descr'
]
=
$rule_data
[
$field
++
];
$flent
[
'icmp_descr'
]
=
$rule_data
[
$field
++
];
break
;
break
;
}
}
}
else
if
(
$flent
[
'protoid'
]
==
'112'
)
{
// CARP
}
else
if
(
$flent
[
'protoid'
]
==
'112'
)
{
// CARP
$flent
[
'type'
]
=
$rule_data
[
$field
++
];
$flent
[
'type'
]
=
$rule_data
[
$field
++
];
$flent
[
'ttl'
]
=
$rule_data
[
$field
++
];
$flent
[
'ttl'
]
=
$rule_data
[
$field
++
];
...
@@ -241,18 +247,18 @@ function parse_filter_line($line) {
...
@@ -241,18 +247,18 @@ function parse_filter_line($line) {
$flent
[
'advskew'
]
=
$rule_data
[
$field
++
];
$flent
[
'advskew'
]
=
$rule_data
[
$field
++
];
$flent
[
'advbase'
]
=
$rule_data
[
$field
++
];
$flent
[
'advbase'
]
=
$rule_data
[
$field
++
];
}
}
}
else
{
log_error
(
sprintf
(
gettext
(
"There was a error parsing rule number: %s. Please report to mailing list or forum."
),
$flent
[
'rulenum'
]));
/* If there isn't a src, a dst, or a time, then the line is unusable/bad */
return
""
;
if
(
trim
(
$flent
[
'src'
])
==
''
||
trim
(
$flent
[
'dst'
])
==
''
||
trim
(
$flent
[
'time'
])
==
''
)
{
log_error
(
sprintf
(
gettext
(
"There was a error parsing rule: %s -- no src or test or time (`%s')"
),
$flent
[
'rulenum'
],
$rule
));
return
''
;
}
}
/* If there is a src, a dst, and a time, then the line should be usable/good */
if
(
!
((
trim
(
$flent
[
'src'
])
==
""
)
||
(
trim
(
$flent
[
'dst'
])
==
""
)
||
(
trim
(
$flent
[
'time'
])
==
""
)))
{
return
$flent
;
return
$flent
;
}
else
{
log_error
(
sprintf
(
gettext
(
"There was a error parsing rule: %s. Please report to mailing list or forum."
),
$errline
));
return
""
;
}
}
}
function
get_port_with_service
(
$port
,
$proto
)
{
function
get_port_with_service
(
$port
,
$proto
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment