forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Justin Pettit <[email protected]> Acked-by: Han Zhou <[email protected]> Acked-by: Ben Pfaff <[email protected]>
- Loading branch information
1 parent
19536b6
commit d383eed
Showing
17 changed files
with
677 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2017 Nicira, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <config.h> | ||
#include "ovn/lib/acl-log.h" | ||
#include <string.h> | ||
#include "flow.h" | ||
#include "openvswitch/json.h" | ||
#include "openvswitch/ofpbuf.h" | ||
#include "openvswitch/vlog.h" | ||
|
||
|
||
VLOG_DEFINE_THIS_MODULE(acl_log); | ||
|
||
const char * | ||
log_verdict_to_string(uint8_t verdict) | ||
{ | ||
if (verdict == LOG_VERDICT_ALLOW) { | ||
return "allow"; | ||
} else if (verdict == LOG_VERDICT_DROP) { | ||
return "drop"; | ||
} else if (verdict == LOG_VERDICT_REJECT) { | ||
return "reject"; | ||
} else { | ||
return "<unknown>"; | ||
} | ||
} | ||
|
||
const char * | ||
log_severity_to_string(uint8_t severity) | ||
{ | ||
if (severity == LOG_SEVERITY_ALERT) { | ||
return "alert"; | ||
} else if (severity == LOG_SEVERITY_WARNING) { | ||
return "warning"; | ||
} else if (severity == LOG_SEVERITY_NOTICE) { | ||
return "notice"; | ||
} else if (severity == LOG_SEVERITY_INFO) { | ||
return "info"; | ||
} else if (severity == LOG_SEVERITY_DEBUG) { | ||
return "debug"; | ||
} else { | ||
return "<unknown>"; | ||
} | ||
} | ||
|
||
uint8_t | ||
log_severity_from_string(const char *name) | ||
{ | ||
if (!strcmp(name, "alert")) { | ||
return LOG_SEVERITY_ALERT; | ||
} else if (!strcmp(name, "warning")) { | ||
return LOG_SEVERITY_WARNING; | ||
} else if (!strcmp(name, "notice")) { | ||
return LOG_SEVERITY_NOTICE; | ||
} else if (!strcmp(name, "info")) { | ||
return LOG_SEVERITY_INFO; | ||
} else if (!strcmp(name, "debug")) { | ||
return LOG_SEVERITY_DEBUG; | ||
} else { | ||
return UINT8_MAX; | ||
} | ||
} | ||
|
||
void | ||
handle_acl_log(const struct flow *headers, struct ofpbuf *userdata) | ||
{ | ||
if (!VLOG_IS_INFO_ENABLED()) { | ||
return; | ||
} | ||
|
||
struct log_pin_header *lph = ofpbuf_try_pull(userdata, sizeof *lph); | ||
if (!lph) { | ||
VLOG_WARN("log data missing"); | ||
return; | ||
} | ||
|
||
size_t name_len = userdata->size; | ||
char *name = name_len ? xmemdup0(userdata->data, name_len) : NULL; | ||
|
||
struct ds ds = DS_EMPTY_INITIALIZER; | ||
ds_put_cstr(&ds, "name="); | ||
json_string_escape(name_len ? name : "<unnamed>", &ds); | ||
ds_put_format(&ds, ", verdict=%s, severity=%s: ", | ||
log_verdict_to_string(lph->verdict), | ||
log_severity_to_string(lph->severity)); | ||
flow_format(&ds, headers, NULL); | ||
|
||
VLOG_INFO("%s", ds_cstr(&ds)); | ||
ds_destroy(&ds); | ||
free(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2017 Nicira, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef ACL_LOG_H | ||
#define ACL_LOG_H 1 | ||
|
||
#include <stdint.h> | ||
#include "openvswitch/types.h" | ||
|
||
struct ofpbuf; | ||
struct flow; | ||
|
||
struct log_pin_header { | ||
uint8_t verdict; /* One of LOG_VERDICT_*. */ | ||
uint8_t severity; /* One of LOG_SEVERITY*. */ | ||
/* Followed by an optional string containing the rule's name. */ | ||
}; | ||
|
||
enum log_verdict { | ||
LOG_VERDICT_ALLOW, | ||
LOG_VERDICT_DROP, | ||
LOG_VERDICT_REJECT, | ||
LOG_VERDICT_UNKNOWN = UINT8_MAX | ||
}; | ||
|
||
const char *log_verdict_to_string(uint8_t verdict); | ||
|
||
|
||
/* Severity levels. Based on RFC5424 levels. */ | ||
#define LOG_SEVERITY_ALERT 1 | ||
#define LOG_SEVERITY_WARNING 4 | ||
#define LOG_SEVERITY_NOTICE 5 | ||
#define LOG_SEVERITY_INFO 6 | ||
#define LOG_SEVERITY_DEBUG 7 | ||
|
||
const char *log_severity_to_string(uint8_t severity); | ||
uint8_t log_severity_from_string(const char *name); | ||
|
||
void handle_acl_log(const struct flow *headers, struct ofpbuf *userdata); | ||
|
||
#endif /* ovn/lib/acl-log.h */ |
Oops, something went wrong.