-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an initial implementation of a dissector to work on netlink messages as received from an nlmon device. Use can use it as follows to monitor netlink traffic to/from the kernel: modprobe nlmon ip link add type nlmon ip link set nlmon0 up netsniff-ng -i nlmon0 ip link set nlmon 0 down ip link del dev nlmon0 rmmod nlmon Fixes: #89 Suggested-by: Daniel Borkmann <[email protected]> Signed-off-by: Tobias Klauser <[email protected]>
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* netsniff-ng - the packet sniffing beast | ||
* Copyright 2014 Tobias Klauser. | ||
* Subject to the GPL, version 2. | ||
*/ | ||
|
||
#include "dissector.h" | ||
#include "dissector_netlink.h" | ||
|
||
#ifdef HAVE_DISSECTOR_PROTOS | ||
static inline void dissector_init_entry(int type) | ||
{ | ||
dissector_set_print_type(&nlmsg_ops, type); | ||
} | ||
|
||
static inline void dissector_init_exit(int type) | ||
{ | ||
dissector_set_print_type(&none_ops, type); | ||
} | ||
#else | ||
static inline void dissector_init_entry(int type __maybe_unused) {} | ||
static inline void dissector_init_exit(int type __maybe_unused) {} | ||
#endif | ||
|
||
void dissector_init_netlink(int fnttype) | ||
{ | ||
dissector_init_entry(fnttype); | ||
dissector_init_exit(fnttype); | ||
} | ||
|
||
void dissector_cleanup_netlink(void) | ||
{ | ||
} |
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,37 @@ | ||
/* | ||
* netsniff-ng - the packet sniffing beast | ||
* Copyright 2014 Tobias Klauser. | ||
* Subject to the GPL, version 2. | ||
*/ | ||
|
||
#ifndef DISSECTOR_NETLINK_H | ||
#define DISSECTOR_NETLINK_H | ||
|
||
#include "protos.h" | ||
|
||
extern void dissector_init_netlink(int fnttype); | ||
extern void dissector_cleanup_netlink(void); | ||
|
||
#ifdef HAVE_DISSECTOR_PROTOS | ||
static inline struct protocol *dissector_get_netlink_entry_point(void) | ||
{ | ||
return &nlmsg_ops; | ||
} | ||
|
||
static inline struct protocol *dissector_get_netlink_exit_point(void) | ||
{ | ||
return &none_ops; | ||
} | ||
#else | ||
static inline struct protocol *dissector_get_netlink_entry_point(void) | ||
{ | ||
return NULL; | ||
} | ||
|
||
static inline struct protocol *dissector_get_netlink_exit_point(void) | ||
{ | ||
return NULL; | ||
} | ||
#endif /* HAVE_DISSECTOR_PROTOS */ | ||
|
||
#endif /* DISSECTOR_NETLINK_H */ |
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,52 @@ | ||
/* | ||
* netsniff-ng - the packet sniffing beast | ||
* Copyright 2014 Tobias Klauser. | ||
* Subject to the GPL, version 2. | ||
*/ | ||
|
||
#include <libnl3/netlink/msg.h> | ||
|
||
#include "pkt_buff.h" | ||
#include "proto.h" | ||
|
||
static void nlmsg(struct pkt_buff *pkt) | ||
{ | ||
struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr)); | ||
char type[32]; | ||
char flags[128]; | ||
|
||
if (hdr == NULL) | ||
return; | ||
|
||
tprintf(" [ NLMSG "); | ||
tprintf("Len %u, ", hdr->nlmsg_len); | ||
tprintf("Type 0x%.4x (%s%s%s), ", hdr->nlmsg_type, | ||
colorize_start(bold), | ||
nl_nlmsgtype2str(hdr->nlmsg_type, type, sizeof(type)), | ||
colorize_end()); | ||
tprintf("Flags 0x%.4x (%s%s%s), ", hdr->nlmsg_flags, | ||
colorize_start(bold), | ||
nl_nlmsg_flags2str(hdr->nlmsg_flags, flags, sizeof(flags)), | ||
colorize_end()); | ||
tprintf("Seq-Nr %u, ", hdr->nlmsg_seq); | ||
tprintf("PID %u", hdr->nlmsg_pid); | ||
tprintf(" ]\n"); | ||
} | ||
|
||
static void nlmsg_less(struct pkt_buff *pkt) | ||
{ | ||
struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr)); | ||
char type[32]; | ||
|
||
if (hdr == NULL) | ||
return; | ||
|
||
tprintf(" NLMSG %u (%s%s%s)", hdr->nlmsg_type, colorize_start(bold), | ||
nl_nlmsgtype2str(hdr->nlmsg_type, type, sizeof(type)), | ||
colorize_end()); | ||
} | ||
|
||
struct protocol nlmsg_ops = { | ||
.print_full = nlmsg, | ||
.print_less = nlmsg_less, | ||
}; |
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