13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/link.h> 16 #include <linux/rtnetlink.h> 19 enum rtnetlink_groups gr_id;
22 { RTNLGRP_LINK,
"link" },
23 { RTNLGRP_NOTIFY,
"notify" },
24 { RTNLGRP_NEIGH,
"neigh" },
26 { RTNLGRP_IPV4_IFADDR,
"ipv4-ifaddr" },
27 { RTNLGRP_IPV4_MROUTE,
"ipv4-mroute" },
28 { RTNLGRP_IPV4_ROUTE,
"ipv4-route" },
29 { RTNLGRP_IPV6_IFADDR,
"ipv6-ifaddr" },
30 { RTNLGRP_IPV6_MROUTE,
"ipv6-mroute" },
31 { RTNLGRP_IPV6_ROUTE,
"ipv6-route" },
32 { RTNLGRP_IPV6_IFINFO,
"ipv6-ifinfo" },
33 { RTNLGRP_DECnet_IFADDR,
"decnet-ifaddr" },
34 { RTNLGRP_DECnet_ROUTE,
"decnet-route" },
35 { RTNLGRP_IPV6_PREFIX,
"ipv6-prefix" },
36 { RTNLGRP_IPV4_NETCONF,
"ipv4-netconf" },
37 { RTNLGRP_IPV6_NETCONF,
"ipv6-netconf" },
38 { RTNLGRP_MPLS_NETCONF,
"mpls-netconf" },
39 { RTNLGRP_NONE, NULL }
42 static void obj_input(
struct nl_object *obj,
void *arg)
47 static int event_input(
struct nl_msg *msg,
void *arg)
49 if (nl_msg_parse(msg, &obj_input, arg) < 0)
50 fprintf(stderr,
"<<EVENT>> Unknown message type\n");
56 static void print_usage(
void)
61 "Usage: nl-monitor [OPTION] [<groups>]\n" 64 " -f, --format=TYPE Output format { brief | details | stats }\n" 65 " -h, --help Show this help.\n" 68 printf(
"Known groups:");
69 for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++)
70 printf(
" %s", known_groups[i].gr_name);
75 int main(
int argc,
char *argv[])
87 sock = nl_cli_alloc_socket();
93 static struct option long_opts[] = {
94 {
"format", 1, 0,
'f' },
98 c = getopt_long(argc, argv,
"f:h", long_opts, &optidx);
104 dp.
dp_type = nl_cli_parse_dumptype(optarg);
112 nl_cli_connect(sock, NETLINK_ROUTE);
114 for (idx = optind; argc > idx; idx++) {
115 for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++) {
116 if (!strcmp(argv[idx], known_groups[i].gr_name)) {
118 if ((err = nl_socket_add_membership(sock, known_groups[i].gr_id)) < 0) {
126 if (known_groups[i].gr_id == RTNLGRP_NONE)
127 fprintf(stderr,
"Warning: Unknown group: %s\n", argv[idx]);
130 nl_cli_link_alloc_cache(sock);
141 retval = select(fd+1, &rfds, NULL, NULL, NULL);
Customized handler specified by the user.
int nl_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Stop parsing altogether and discard remaining messages.
int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated with the socket.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
int nl_recvmsgs_default(struct nl_sock *sk)
Receive a set of message from a netlink socket using handlers in nl_sock.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Dump all attributes including statistics.