osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libnetlink.c RTnetlink service routines. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <unistd.h> |
| 16 | #include <syslog.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <net/if_arp.h> |
| 19 | #include <sys/socket.h> |
| 20 | #include <netinet/in.h> |
| 21 | #include <string.h> |
| 22 | #include <errno.h> |
| 23 | #include <time.h> |
| 24 | #include <sys/uio.h> |
| 25 | |
| 26 | #include "libnetlink.h" |
| 27 | |
Patrick McHardy | 7f03191 | 2009-10-28 20:50:48 +0100 | [diff] [blame] | 28 | int rcvbuf = 1024 * 1024; |
| 29 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 30 | void rtnl_close(struct rtnl_handle *rth) |
| 31 | { |
Stephen Hemminger | 3bfa73f | 2006-09-26 10:41:57 -0700 | [diff] [blame] | 32 | if (rth->fd >= 0) { |
| 33 | close(rth->fd); |
| 34 | rth->fd = -1; |
| 35 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 36 | } |
| 37 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 38 | int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, |
| 39 | int protocol) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 40 | { |
shemminger | f332d16 | 2005-07-05 22:37:15 +0000 | [diff] [blame] | 41 | socklen_t addr_len; |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 42 | int sndbuf = 32768; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 43 | |
Stephen Hemminger | b16621c | 2007-05-10 19:33:21 -0700 | [diff] [blame] | 44 | memset(rth, 0, sizeof(*rth)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 45 | |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 46 | rth->fd = socket(AF_NETLINK, SOCK_RAW, protocol); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 47 | if (rth->fd < 0) { |
| 48 | perror("Cannot open netlink socket"); |
| 49 | return -1; |
| 50 | } |
| 51 | |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 52 | if (setsockopt(rth->fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) { |
| 53 | perror("SO_SNDBUF"); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | if (setsockopt(rth->fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)) < 0) { |
| 58 | perror("SO_RCVBUF"); |
| 59 | return -1; |
| 60 | } |
| 61 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 62 | memset(&rth->local, 0, sizeof(rth->local)); |
| 63 | rth->local.nl_family = AF_NETLINK; |
| 64 | rth->local.nl_groups = subscriptions; |
| 65 | |
| 66 | if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) { |
| 67 | perror("Cannot bind netlink socket"); |
| 68 | return -1; |
| 69 | } |
| 70 | addr_len = sizeof(rth->local); |
| 71 | if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) { |
| 72 | perror("Cannot getsockname"); |
| 73 | return -1; |
| 74 | } |
| 75 | if (addr_len != sizeof(rth->local)) { |
| 76 | fprintf(stderr, "Wrong address length %d\n", addr_len); |
| 77 | return -1; |
| 78 | } |
| 79 | if (rth->local.nl_family != AF_NETLINK) { |
| 80 | fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family); |
| 81 | return -1; |
| 82 | } |
| 83 | rth->seq = time(NULL); |
| 84 | return 0; |
| 85 | } |
| 86 | |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 87 | int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) |
| 88 | { |
| 89 | return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); |
| 90 | } |
| 91 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 92 | int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) |
| 93 | { |
| 94 | struct { |
| 95 | struct nlmsghdr nlh; |
| 96 | struct rtgenmsg g; |
| 97 | } req; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 98 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 99 | memset(&req, 0, sizeof(req)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 100 | req.nlh.nlmsg_len = sizeof(req); |
| 101 | req.nlh.nlmsg_type = type; |
Masatake YAMATO | aa38c3e | 2012-01-19 14:16:12 -0800 | [diff] [blame^] | 102 | req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 103 | req.nlh.nlmsg_pid = 0; |
| 104 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; |
| 105 | req.g.rtgen_family = family; |
| 106 | |
Stephen Hemminger | f31a37f | 2008-01-31 21:38:58 -0800 | [diff] [blame] | 107 | return send(rth->fd, (void*)&req, sizeof(req), 0); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Stephen Hemminger | 6cf8398 | 2011-12-23 10:40:04 -0800 | [diff] [blame] | 110 | int rtnl_send(struct rtnl_handle *rth, const void *buf, int len) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 111 | { |
Stephen Hemminger | f31a37f | 2008-01-31 21:38:58 -0800 | [diff] [blame] | 112 | return send(rth->fd, buf, len, 0); |
| 113 | } |
| 114 | |
Stephen Hemminger | 6cf8398 | 2011-12-23 10:40:04 -0800 | [diff] [blame] | 115 | int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) |
Stephen Hemminger | f31a37f | 2008-01-31 21:38:58 -0800 | [diff] [blame] | 116 | { |
Stephen Hemminger | 54bb35c | 2008-01-26 11:09:42 -0800 | [diff] [blame] | 117 | struct nlmsghdr *h; |
| 118 | int status; |
| 119 | char resp[1024]; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 120 | |
Stephen Hemminger | f31a37f | 2008-01-31 21:38:58 -0800 | [diff] [blame] | 121 | status = send(rth->fd, buf, len, 0); |
Stephen Hemminger | 54bb35c | 2008-01-26 11:09:42 -0800 | [diff] [blame] | 122 | if (status < 0) |
| 123 | return status; |
| 124 | |
Stephen Hemminger | 2d8240f | 2009-07-13 10:15:23 -0700 | [diff] [blame] | 125 | /* Check for immediate errors */ |
| 126 | status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT|MSG_PEEK); |
Stephen Hemminger | 54bb35c | 2008-01-26 11:09:42 -0800 | [diff] [blame] | 127 | if (status < 0) { |
| 128 | if (errno == EAGAIN) |
| 129 | return 0; |
| 130 | return -1; |
| 131 | } |
| 132 | |
| 133 | for (h = (struct nlmsghdr *)resp; NLMSG_OK(h, status); |
| 134 | h = NLMSG_NEXT(h, status)) { |
| 135 | if (h->nlmsg_type == NLMSG_ERROR) { |
| 136 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
| 137 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) |
| 138 | fprintf(stderr, "ERROR truncated\n"); |
| 139 | else |
| 140 | errno = -err->error; |
Sven Anders | 24f3818 | 2009-11-10 09:07:26 -0800 | [diff] [blame] | 141 | return -1; |
Stephen Hemminger | 54bb35c | 2008-01-26 11:09:42 -0800 | [diff] [blame] | 142 | } |
Stephen Hemminger | 54bb35c | 2008-01-26 11:09:42 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return 0; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) |
| 149 | { |
| 150 | struct nlmsghdr nlh; |
Stephen Hemminger | 6cf8398 | 2011-12-23 10:40:04 -0800 | [diff] [blame] | 151 | struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 152 | struct iovec iov[2] = { |
| 153 | { .iov_base = &nlh, .iov_len = sizeof(nlh) }, |
| 154 | { .iov_base = req, .iov_len = len } |
| 155 | }; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 156 | struct msghdr msg = { |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 157 | .msg_name = &nladdr, |
| 158 | .msg_namelen = sizeof(nladdr), |
| 159 | .msg_iov = iov, |
| 160 | .msg_iovlen = 2, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 163 | nlh.nlmsg_len = NLMSG_LENGTH(len); |
| 164 | nlh.nlmsg_type = type; |
Masatake YAMATO | aa38c3e | 2012-01-19 14:16:12 -0800 | [diff] [blame^] | 165 | nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 166 | nlh.nlmsg_pid = 0; |
| 167 | nlh.nlmsg_seq = rth->dump = ++rth->seq; |
| 168 | |
| 169 | return sendmsg(rth->fd, &msg, 0); |
| 170 | } |
| 171 | |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 172 | int rtnl_dump_filter_l(struct rtnl_handle *rth, |
| 173 | const struct rtnl_dump_filter_arg *arg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 174 | { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 175 | struct sockaddr_nl nladdr; |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 176 | struct iovec iov; |
| 177 | struct msghdr msg = { |
| 178 | .msg_name = &nladdr, |
| 179 | .msg_namelen = sizeof(nladdr), |
| 180 | .msg_iov = &iov, |
| 181 | .msg_iovlen = 1, |
| 182 | }; |
| 183 | char buf[16384]; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 184 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 185 | iov.iov_base = buf; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 186 | while (1) { |
| 187 | int status; |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 188 | const struct rtnl_dump_filter_arg *a; |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 189 | int found_done = 0; |
| 190 | int msglen = 0; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 191 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 192 | iov.iov_len = sizeof(buf); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 193 | status = recvmsg(rth->fd, &msg, 0); |
| 194 | |
| 195 | if (status < 0) { |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 196 | if (errno == EINTR || errno == EAGAIN) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 197 | continue; |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 198 | fprintf(stderr, "netlink receive error %s (%d)\n", |
| 199 | strerror(errno), errno); |
| 200 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 201 | } |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 202 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 203 | if (status == 0) { |
| 204 | fprintf(stderr, "EOF on netlink\n"); |
| 205 | return -1; |
| 206 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 207 | |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 208 | for (a = arg; a->filter; a++) { |
| 209 | struct nlmsghdr *h = (struct nlmsghdr*)buf; |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 210 | msglen = status; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 211 | |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 212 | while (NLMSG_OK(h, msglen)) { |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 213 | int err; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 214 | |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 215 | if (nladdr.nl_pid != 0 || |
| 216 | h->nlmsg_pid != rth->local.nl_pid || |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 217 | h->nlmsg_seq != rth->dump) |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 218 | goto skip_it; |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 219 | |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 220 | if (h->nlmsg_type == NLMSG_DONE) { |
| 221 | found_done = 1; |
| 222 | break; /* process next filter */ |
| 223 | } |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 224 | if (h->nlmsg_type == NLMSG_ERROR) { |
| 225 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
| 226 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { |
| 227 | fprintf(stderr, |
| 228 | "ERROR truncated\n"); |
| 229 | } else { |
| 230 | errno = -err->error; |
| 231 | perror("RTNETLINK answers"); |
| 232 | } |
| 233 | return -1; |
| 234 | } |
| 235 | err = a->filter(&nladdr, h, a->arg1); |
| 236 | if (err < 0) |
| 237 | return err; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 238 | |
| 239 | skip_it: |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 240 | h = NLMSG_NEXT(h, msglen); |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 241 | } |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | if (found_done) |
| 245 | return 0; |
| 246 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 247 | if (msg.msg_flags & MSG_TRUNC) { |
| 248 | fprintf(stderr, "Message truncated\n"); |
| 249 | continue; |
| 250 | } |
Ben Greear | 3bc1c4f | 2010-08-16 10:00:08 -0700 | [diff] [blame] | 251 | if (msglen) { |
| 252 | fprintf(stderr, "!!!Remnant of size %d\n", msglen); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 253 | exit(1); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 258 | int rtnl_dump_filter(struct rtnl_handle *rth, |
| 259 | rtnl_filter_t filter, |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 260 | void *arg1) |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 261 | { |
| 262 | const struct rtnl_dump_filter_arg a[2] = { |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 263 | { .filter = filter, .arg1 = arg1, }, |
| 264 | { .filter = NULL, .arg1 = NULL, }, |
Simon Horman | b49240e | 2009-12-03 12:08:27 +1100 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | return rtnl_dump_filter_l(rth, a); |
| 268 | } |
| 269 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 270 | int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 271 | unsigned groups, struct nlmsghdr *answer) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 272 | { |
| 273 | int status; |
| 274 | unsigned seq; |
| 275 | struct nlmsghdr *h; |
| 276 | struct sockaddr_nl nladdr; |
shemminger | fb22975 | 2005-10-04 23:15:32 +0000 | [diff] [blame] | 277 | struct iovec iov = { |
| 278 | .iov_base = (void*) n, |
| 279 | .iov_len = n->nlmsg_len |
| 280 | }; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 281 | struct msghdr msg = { |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 282 | .msg_name = &nladdr, |
| 283 | .msg_namelen = sizeof(nladdr), |
| 284 | .msg_iov = &iov, |
| 285 | .msg_iovlen = 1, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 286 | }; |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 287 | char buf[16384]; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 288 | |
| 289 | memset(&nladdr, 0, sizeof(nladdr)); |
| 290 | nladdr.nl_family = AF_NETLINK; |
| 291 | nladdr.nl_pid = peer; |
| 292 | nladdr.nl_groups = groups; |
| 293 | |
| 294 | n->nlmsg_seq = seq = ++rtnl->seq; |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 295 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 296 | if (answer == NULL) |
| 297 | n->nlmsg_flags |= NLM_F_ACK; |
| 298 | |
| 299 | status = sendmsg(rtnl->fd, &msg, 0); |
| 300 | |
| 301 | if (status < 0) { |
| 302 | perror("Cannot talk to rtnetlink"); |
| 303 | return -1; |
| 304 | } |
| 305 | |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 306 | memset(buf,0,sizeof(buf)); |
| 307 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 308 | iov.iov_base = buf; |
| 309 | |
| 310 | while (1) { |
| 311 | iov.iov_len = sizeof(buf); |
| 312 | status = recvmsg(rtnl->fd, &msg, 0); |
| 313 | |
| 314 | if (status < 0) { |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 315 | if (errno == EINTR || errno == EAGAIN) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 316 | continue; |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 317 | fprintf(stderr, "netlink receive error %s (%d)\n", |
| 318 | strerror(errno), errno); |
| 319 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 320 | } |
| 321 | if (status == 0) { |
| 322 | fprintf(stderr, "EOF on netlink\n"); |
| 323 | return -1; |
| 324 | } |
| 325 | if (msg.msg_namelen != sizeof(nladdr)) { |
| 326 | fprintf(stderr, "sender address length == %d\n", msg.msg_namelen); |
| 327 | exit(1); |
| 328 | } |
| 329 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 330 | int len = h->nlmsg_len; |
| 331 | int l = len - sizeof(*h); |
| 332 | |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 333 | if (l < 0 || len>status) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 334 | if (msg.msg_flags & MSG_TRUNC) { |
| 335 | fprintf(stderr, "Truncated message\n"); |
| 336 | return -1; |
| 337 | } |
| 338 | fprintf(stderr, "!!!malformed message: len=%d\n", len); |
| 339 | exit(1); |
| 340 | } |
| 341 | |
org[shemminger]!shemminger | 10f57ef | 2004-06-07 22:04:04 +0000 | [diff] [blame] | 342 | if (nladdr.nl_pid != peer || |
| 343 | h->nlmsg_pid != rtnl->local.nl_pid || |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 344 | h->nlmsg_seq != seq) { |
shemminger | 4cca16f | 2006-03-10 23:31:46 +0000 | [diff] [blame] | 345 | /* Don't forget to skip that message. */ |
| 346 | status -= NLMSG_ALIGN(len); |
| 347 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 348 | continue; |
| 349 | } |
| 350 | |
| 351 | if (h->nlmsg_type == NLMSG_ERROR) { |
| 352 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
| 353 | if (l < sizeof(struct nlmsgerr)) { |
| 354 | fprintf(stderr, "ERROR truncated\n"); |
| 355 | } else { |
| 356 | errno = -err->error; |
| 357 | if (errno == 0) { |
| 358 | if (answer) |
| 359 | memcpy(answer, h, h->nlmsg_len); |
| 360 | return 0; |
| 361 | } |
| 362 | perror("RTNETLINK answers"); |
| 363 | } |
| 364 | return -1; |
| 365 | } |
| 366 | if (answer) { |
| 367 | memcpy(answer, h, h->nlmsg_len); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | fprintf(stderr, "Unexpected reply!!!\n"); |
| 372 | |
| 373 | status -= NLMSG_ALIGN(len); |
| 374 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
| 375 | } |
| 376 | if (msg.msg_flags & MSG_TRUNC) { |
| 377 | fprintf(stderr, "Message truncated\n"); |
| 378 | continue; |
| 379 | } |
| 380 | if (status) { |
| 381 | fprintf(stderr, "!!!Remnant of size %d\n", status); |
| 382 | exit(1); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 387 | int rtnl_listen(struct rtnl_handle *rtnl, |
osdl.net!shemminger | 6dc9f01 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 388 | rtnl_filter_t handler, |
| 389 | void *jarg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 390 | { |
| 391 | int status; |
| 392 | struct nlmsghdr *h; |
| 393 | struct sockaddr_nl nladdr; |
| 394 | struct iovec iov; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 395 | struct msghdr msg = { |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 396 | .msg_name = &nladdr, |
| 397 | .msg_namelen = sizeof(nladdr), |
| 398 | .msg_iov = &iov, |
| 399 | .msg_iovlen = 1, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 400 | }; |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 401 | char buf[8192]; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 402 | |
| 403 | memset(&nladdr, 0, sizeof(nladdr)); |
| 404 | nladdr.nl_family = AF_NETLINK; |
| 405 | nladdr.nl_pid = 0; |
| 406 | nladdr.nl_groups = 0; |
| 407 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 408 | iov.iov_base = buf; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 409 | while (1) { |
| 410 | iov.iov_len = sizeof(buf); |
| 411 | status = recvmsg(rtnl->fd, &msg, 0); |
| 412 | |
| 413 | if (status < 0) { |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 414 | if (errno == EINTR || errno == EAGAIN) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 415 | continue; |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 416 | fprintf(stderr, "netlink receive error %s (%d)\n", |
| 417 | strerror(errno), errno); |
Patrick McHardy | 7f03191 | 2009-10-28 20:50:48 +0100 | [diff] [blame] | 418 | if (errno == ENOBUFS) |
| 419 | continue; |
Stephen Hemminger | aa8032e | 2008-01-25 15:39:09 -0800 | [diff] [blame] | 420 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 421 | } |
| 422 | if (status == 0) { |
| 423 | fprintf(stderr, "EOF on netlink\n"); |
| 424 | return -1; |
| 425 | } |
| 426 | if (msg.msg_namelen != sizeof(nladdr)) { |
| 427 | fprintf(stderr, "Sender address length == %d\n", msg.msg_namelen); |
| 428 | exit(1); |
| 429 | } |
| 430 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { |
| 431 | int err; |
| 432 | int len = h->nlmsg_len; |
| 433 | int l = len - sizeof(*h); |
| 434 | |
| 435 | if (l<0 || len>status) { |
| 436 | if (msg.msg_flags & MSG_TRUNC) { |
| 437 | fprintf(stderr, "Truncated message\n"); |
| 438 | return -1; |
| 439 | } |
| 440 | fprintf(stderr, "!!!malformed message: len=%d\n", len); |
| 441 | exit(1); |
| 442 | } |
| 443 | |
| 444 | err = handler(&nladdr, h, jarg); |
| 445 | if (err < 0) |
| 446 | return err; |
| 447 | |
| 448 | status -= NLMSG_ALIGN(len); |
| 449 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
| 450 | } |
| 451 | if (msg.msg_flags & MSG_TRUNC) { |
| 452 | fprintf(stderr, "Message truncated\n"); |
| 453 | continue; |
| 454 | } |
| 455 | if (status) { |
| 456 | fprintf(stderr, "!!!Remnant of size %d\n", status); |
| 457 | exit(1); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
osdl.net!shemminger | 6dc9f01 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 462 | int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, |
| 463 | void *jarg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 464 | { |
| 465 | int status; |
| 466 | struct sockaddr_nl nladdr; |
| 467 | char buf[8192]; |
| 468 | struct nlmsghdr *h = (void*)buf; |
| 469 | |
| 470 | memset(&nladdr, 0, sizeof(nladdr)); |
| 471 | nladdr.nl_family = AF_NETLINK; |
| 472 | nladdr.nl_pid = 0; |
| 473 | nladdr.nl_groups = 0; |
| 474 | |
| 475 | while (1) { |
Stephen Hemminger | 2dd9f8e | 2011-06-20 14:34:46 -0700 | [diff] [blame] | 476 | int err, len; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 477 | int l; |
| 478 | |
| 479 | status = fread(&buf, 1, sizeof(*h), rtnl); |
| 480 | |
| 481 | if (status < 0) { |
| 482 | if (errno == EINTR) |
| 483 | continue; |
| 484 | perror("rtnl_from_file: fread"); |
| 485 | return -1; |
| 486 | } |
| 487 | if (status == 0) |
| 488 | return 0; |
| 489 | |
| 490 | len = h->nlmsg_len; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 491 | l = len - sizeof(*h); |
| 492 | |
| 493 | if (l<0 || len>sizeof(buf)) { |
| 494 | fprintf(stderr, "!!!malformed message: len=%d @%lu\n", |
| 495 | len, ftell(rtnl)); |
| 496 | return -1; |
| 497 | } |
| 498 | |
| 499 | status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl); |
| 500 | |
| 501 | if (status < 0) { |
| 502 | perror("rtnl_from_file: fread"); |
| 503 | return -1; |
| 504 | } |
| 505 | if (status < l) { |
| 506 | fprintf(stderr, "rtnl-from_file: truncated message\n"); |
| 507 | return -1; |
| 508 | } |
| 509 | |
| 510 | err = handler(&nladdr, h, jarg); |
| 511 | if (err < 0) |
| 512 | return err; |
| 513 | } |
| 514 | } |
| 515 | |
Stephen Hemminger | 2aa3dd2 | 2011-12-23 10:43:54 -0800 | [diff] [blame] | 516 | int addattr(struct nlmsghdr *n, int maxlen, int type) |
| 517 | { |
| 518 | return addattr_l(n, maxlen, type, NULL, 0); |
| 519 | } |
| 520 | |
| 521 | int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data) |
| 522 | { |
| 523 | return addattr_l(n, maxlen, type, &data, sizeof(__u8)); |
| 524 | } |
| 525 | |
| 526 | int addattr16(struct nlmsghdr *n, int maxlen, int type, __u16 data) |
| 527 | { |
| 528 | return addattr_l(n, maxlen, type, &data, sizeof(__u16)); |
| 529 | } |
| 530 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 531 | int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) |
| 532 | { |
Stephen Hemminger | 2aa3dd2 | 2011-12-23 10:43:54 -0800 | [diff] [blame] | 533 | return addattr_l(n, maxlen, type, &data, sizeof(__u32)); |
| 534 | } |
| 535 | |
| 536 | int addattr64(struct nlmsghdr *n, int maxlen, int type, __u64 data) |
| 537 | { |
| 538 | return addattr_l(n, maxlen, type, &data, sizeof(__u64)); |
| 539 | } |
| 540 | |
| 541 | int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *str) |
| 542 | { |
| 543 | return addattr_l(n, maxlen, type, str, strlen(str)+1); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 544 | } |
| 545 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 546 | int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, |
osdl.net!shemminger | 6dc9f01 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 547 | int alen) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 548 | { |
| 549 | int len = RTA_LENGTH(alen); |
| 550 | struct rtattr *rta; |
| 551 | |
net[shemminger]!shemminger | 3dabdbb | 2005-03-30 18:18:12 +0000 | [diff] [blame] | 552 | if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 553 | fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 554 | return -1; |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 555 | } |
6!tgraf | 07f9436 | 2005-01-18 13:58:49 +0000 | [diff] [blame] | 556 | rta = NLMSG_TAIL(n); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 557 | rta->rta_type = type; |
| 558 | rta->rta_len = len; |
| 559 | memcpy(RTA_DATA(rta), data, alen); |
net[shemminger]!shemminger | 3dabdbb | 2005-03-30 18:18:12 +0000 | [diff] [blame] | 560 | n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 561 | return 0; |
| 562 | } |
| 563 | |
6!tgraf | 07f9436 | 2005-01-18 13:58:49 +0000 | [diff] [blame] | 564 | int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len) |
| 565 | { |
| 566 | if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) { |
| 567 | fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen); |
| 568 | return -1; |
| 569 | } |
| 570 | |
| 571 | memcpy(NLMSG_TAIL(n), data, len); |
| 572 | memset((void *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len); |
| 573 | n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len); |
| 574 | return 0; |
| 575 | } |
| 576 | |
Patrick McHardy | 2f90c9c | 2007-08-14 11:21:19 -0700 | [diff] [blame] | 577 | struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type) |
| 578 | { |
| 579 | struct rtattr *nest = NLMSG_TAIL(n); |
| 580 | |
| 581 | addattr_l(n, maxlen, type, NULL, 0); |
| 582 | return nest; |
| 583 | } |
| 584 | |
| 585 | int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest) |
| 586 | { |
| 587 | nest->rta_len = (void *)NLMSG_TAIL(n) - (void *)nest; |
| 588 | return n->nlmsg_len; |
| 589 | } |
| 590 | |
| 591 | struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, |
| 592 | const void *data, int len) |
| 593 | { |
| 594 | struct rtattr *start = NLMSG_TAIL(n); |
| 595 | |
| 596 | addattr_l(n, maxlen, type, data, len); |
| 597 | addattr_nest(n, maxlen, type); |
| 598 | return start; |
| 599 | } |
| 600 | |
| 601 | int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *start) |
| 602 | { |
| 603 | struct rtattr *nest = (void *)start + NLMSG_ALIGN(start->rta_len); |
| 604 | |
| 605 | start->rta_len = (void *)NLMSG_TAIL(n) - (void *)start; |
| 606 | addattr_nest_end(n, nest); |
| 607 | return n->nlmsg_len; |
| 608 | } |
| 609 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 610 | int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data) |
| 611 | { |
| 612 | int len = RTA_LENGTH(4); |
| 613 | struct rtattr *subrta; |
| 614 | |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 615 | if (RTA_ALIGN(rta->rta_len) + len > maxlen) { |
| 616 | fprintf(stderr,"rta_addattr32: Error! max allowed bound %d exceeded\n",maxlen); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 617 | return -1; |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 618 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 619 | subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); |
| 620 | subrta->rta_type = type; |
| 621 | subrta->rta_len = len; |
| 622 | memcpy(RTA_DATA(subrta), &data, 4); |
| 623 | rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; |
| 624 | return 0; |
| 625 | } |
| 626 | |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 627 | int rta_addattr_l(struct rtattr *rta, int maxlen, int type, |
osdl.net!shemminger | 6dc9f01 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 628 | const void *data, int alen) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 629 | { |
| 630 | struct rtattr *subrta; |
| 631 | int len = RTA_LENGTH(alen); |
| 632 | |
net[shemminger]!shemminger | 3dabdbb | 2005-03-30 18:18:12 +0000 | [diff] [blame] | 633 | if (RTA_ALIGN(rta->rta_len) + RTA_ALIGN(len) > maxlen) { |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 634 | fprintf(stderr,"rta_addattr_l: Error! max allowed bound %d exceeded\n",maxlen); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 635 | return -1; |
osdl.net!shemminger | 007d3a3 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 636 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 637 | subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); |
| 638 | subrta->rta_type = type; |
| 639 | subrta->rta_len = len; |
| 640 | memcpy(RTA_DATA(subrta), data, alen); |
net[shemminger]!shemminger | 3dabdbb | 2005-03-30 18:18:12 +0000 | [diff] [blame] | 641 | rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 642 | return 0; |
| 643 | } |
| 644 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 645 | int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) |
| 646 | { |
osdl.net!shemminger | 175e244 | 2005-02-07 18:17:38 +0000 | [diff] [blame] | 647 | memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 648 | while (RTA_OK(rta, len)) { |
Williams, Mitch A | 6e46ec8 | 2010-02-10 01:46:47 +0000 | [diff] [blame] | 649 | if ((rta->rta_type <= max) && (!tb[rta->rta_type])) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 650 | tb[rta->rta_type] = rta; |
| 651 | rta = RTA_NEXT(rta,len); |
| 652 | } |
| 653 | if (len) |
| 654 | fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len); |
| 655 | return 0; |
| 656 | } |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 657 | |
| 658 | int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len) |
| 659 | { |
| 660 | int i = 0; |
osdl.net!shemminger | 175e244 | 2005-02-07 18:17:38 +0000 | [diff] [blame] | 661 | |
| 662 | memset(tb, 0, sizeof(struct rtattr *) * max); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 663 | while (RTA_OK(rta, len)) { |
osdl.net!shemminger | 175e244 | 2005-02-07 18:17:38 +0000 | [diff] [blame] | 664 | if (rta->rta_type <= max && i < max) |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 665 | tb[i++] = rta; |
| 666 | rta = RTA_NEXT(rta,len); |
| 667 | } |
| 668 | if (len) |
| 669 | fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len); |
| 670 | return i; |
| 671 | } |
Patrick McHardy | 2f90c9c | 2007-08-14 11:21:19 -0700 | [diff] [blame] | 672 | |
| 673 | int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, |
| 674 | int len) |
| 675 | { |
| 676 | if (RTA_PAYLOAD(rta) < len) |
| 677 | return -1; |
| 678 | if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) { |
| 679 | rta = RTA_DATA(rta) + RTA_ALIGN(len); |
| 680 | return parse_rtattr_nested(tb, max, rta); |
| 681 | } |
Stephen Hemminger | 037c635 | 2007-12-10 11:34:40 -0800 | [diff] [blame] | 682 | memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); |
Patrick McHardy | 2f90c9c | 2007-08-14 11:21:19 -0700 | [diff] [blame] | 683 | return 0; |
| 684 | } |