Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dropwatch-diff
diff -u dropwatch/src/main.c /root/src/dropwatch/src/main.c
--- dropwatch/src/main.c 2020-10-20 20:41:06.825595602 +0000
+++ /root/src/dropwatch/src/main.c 2020-09-07 20:47:35.230847265 +0000
@@ -50,6 +50,17 @@
struct ack_list ack_list_head = {NULL};
+struct symbol_exclude {
+ char *sym;
+ LIST_ENTRY(symbol_exclude) list;
+};
+
+LIST_HEAD(symbol_excludes, symbol_exclude);
+
+struct symbol_excludes symbol_excludes_list_head = {NULL};
+
+unsigned min_len = 0;
+unsigned only_port = 0;
unsigned long alimit = 0;
unsigned long acount = 0;
unsigned long trunc_len = 0;
@@ -435,6 +446,24 @@
free_netlink_msg(msg);
}
+static bool is_port(struct nlattr *attr, unsigned port) {
+ struct nlattr *attrs[NET_DM_ATTR_PORT_MAX + 1];
+ int err;
+
+ err = nla_parse_nested(attrs, NET_DM_ATTR_PORT_MAX, attr,
+ net_dm_port_policy);
+ if (err)
+ return false;
+ if (!attrs[NET_DM_ATTR_PORT_NETDEV_IFINDEX]) {
+ printf("no ifindex\n");
+ return false;
+ }
+
+ unsigned iport = nla_get_u32(attrs[NET_DM_ATTR_PORT_NETDEV_IFINDEX]);
+
+ return iport == port;
+}
+
void print_nested_port(struct nlattr *attr, const char *dir)
{
struct nlattr *attrs[NET_DM_ATTR_PORT_MAX + 1];
@@ -486,6 +515,27 @@
if (err)
goto out_free;
+ if (attrs[NET_DM_ATTR_PC] && attrs[NET_DM_ATTR_SYMBOL]) {
+ struct symbol_exclude *ex = NULL;
+ char *sym = nla_get_string(attrs[NET_DM_ATTR_SYMBOL]);
+ LIST_FOREACH(ex, &symbol_excludes_list_head, list) {
+ if(strcasestr(sym, ex->sym)) {
+ goto out_free;
+ }
+ }
+ }
+
+ if (attrs[NET_DM_ATTR_IN_PORT] && only_port != 0) {
+ if(!is_port(attrs[NET_DM_ATTR_IN_PORT], only_port))
+ goto out_free;
+ }
+
+ if (min_len != 0 && attrs[NET_DM_ATTR_ORIG_LEN]) {
+ if(nla_get_u32(attrs[NET_DM_ATTR_ORIG_LEN]) < min_len) {
+ goto out_free;
+ }
+ }
+
if (attrs[NET_DM_ATTR_PC] && attrs[NET_DM_ATTR_SYMBOL])
printf("drop at: %s (0x%" PRIx64 ")\n",
nla_get_string(attrs[NET_DM_ATTR_SYMBOL]),
@@ -891,6 +941,24 @@
goto next_input;
}
+ if (!strncmp(input, "exclude sym", strlen("exclude sym"))) {
+ int i = 0;
+ char *cp = input;
+ for(cp = strsep(&input, " "); cp; cp = strsep(&input, " ")) {
+ if(*cp) {
+ i += 1;
+ if(i > 2) {
+ struct symbol_exclude *x = calloc(1, sizeof(*x));
+ x->sym = cp;
+ LIST_INSERT_HEAD(&symbol_excludes_list_head, x, list);
+ printf("excluding %s\n", x->sym);
+ }
+ }
+ }
+
+ goto next_input;
+ }
+
if (!strncmp(input, "set", 3)) {
char *ninput = input+4;
if (!strncmp(ninput, "alertlimit", 10)) {
@@ -907,6 +975,14 @@
state = STATE_RQST_ALERT_MODE_PACKET;
break;
}
+ } else if (!strncmp(ninput, "minlen", 6)) {
+ min_len = strtoul(ninput + 7, NULL, 10);
+ printf("only recording drops for len >= %d\n", min_len);
+ break;
+ } else if (!strncmp(ninput, "onlyport", 8)) {
+ only_port = strtoul(ninput + 9, NULL, 10);
+ printf("only recording drops to port %d\n", only_port);
+ break;
} else if (!strncmp(ninput, "trunc", 5)) {
trunc_len = strtoul(ninput + 6, NULL, 10);
state = STATE_RQST_TRUNC_LEN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.