source: MondoRescue/branches/stable/mindi-busybox/networking/libiproute/libnetlink.c@ 1770

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 16 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File size: 8.9 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * libnetlink.c RTnetlink service routines.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 *
12 */
13
14#include <sys/socket.h>
15#include <sys/uio.h>
16
17#include "libbb.h"
18#include "libnetlink.h"
19
20void rtnl_close(struct rtnl_handle *rth)
21{
22 close(rth->fd);
23}
24
25int xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/)
26{
27 socklen_t addr_len;
28
29 memset(rth, 0, sizeof(rth));
30
31 rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
32
33 memset(&rth->local, 0, sizeof(rth->local));
34 rth->local.nl_family = AF_NETLINK;
35 /*rth->local.nl_groups = subscriptions;*/
36
37 xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local));
38 addr_len = sizeof(rth->local);
39 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0)
40 bb_perror_msg_and_die("cannot getsockname");
41 if (addr_len != sizeof(rth->local))
42 bb_error_msg_and_die("wrong address length %d", addr_len);
43 if (rth->local.nl_family != AF_NETLINK)
44 bb_error_msg_and_die("wrong address family %d", rth->local.nl_family);
45 rth->seq = time(NULL);
46 return 0;
47}
48
49int xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
50{
51 struct {
52 struct nlmsghdr nlh;
53 struct rtgenmsg g;
54 } req;
55 struct sockaddr_nl nladdr;
56
57 memset(&nladdr, 0, sizeof(nladdr));
58 nladdr.nl_family = AF_NETLINK;
59
60 req.nlh.nlmsg_len = sizeof(req);
61 req.nlh.nlmsg_type = type;
62 req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
63 req.nlh.nlmsg_pid = 0;
64 req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
65 req.g.rtgen_family = family;
66
67 return xsendto(rth->fd, (void*)&req, sizeof(req),
68 (struct sockaddr*)&nladdr, sizeof(nladdr));
69}
70
71int rtnl_send(struct rtnl_handle *rth, char *buf, int len)
72{
73 struct sockaddr_nl nladdr;
74
75 memset(&nladdr, 0, sizeof(nladdr));
76 nladdr.nl_family = AF_NETLINK;
77
78 return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr));
79}
80
81int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
82{
83 struct nlmsghdr nlh;
84 struct sockaddr_nl nladdr;
85 struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } };
86 struct msghdr msg = {
87 (void*)&nladdr, sizeof(nladdr),
88 iov, 2,
89 NULL, 0,
90 0
91 };
92
93 memset(&nladdr, 0, sizeof(nladdr));
94 nladdr.nl_family = AF_NETLINK;
95
96 nlh.nlmsg_len = NLMSG_LENGTH(len);
97 nlh.nlmsg_type = type;
98 nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
99 nlh.nlmsg_pid = 0;
100 nlh.nlmsg_seq = rth->dump = ++rth->seq;
101
102 return sendmsg(rth->fd, &msg, 0);
103}
104
105static int rtnl_dump_filter(struct rtnl_handle *rth,
106 int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
107 void *arg1/*,
108 int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
109 void *arg2*/)
110{
111 char buf[8192];
112 struct sockaddr_nl nladdr;
113 struct iovec iov = { buf, sizeof(buf) };
114
115 while (1) {
116 int status;
117 struct nlmsghdr *h;
118
119 struct msghdr msg = {
120 (void*)&nladdr, sizeof(nladdr),
121 &iov, 1,
122 NULL, 0,
123 0
124 };
125
126 status = recvmsg(rth->fd, &msg, 0);
127
128 if (status < 0) {
129 if (errno == EINTR)
130 continue;
131 bb_perror_msg("OVERRUN");
132 continue;
133 }
134 if (status == 0) {
135 bb_error_msg("EOF on netlink");
136 return -1;
137 }
138 if (msg.msg_namelen != sizeof(nladdr)) {
139 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen);
140 }
141
142 h = (struct nlmsghdr*)buf;
143 while (NLMSG_OK(h, status)) {
144 int err;
145
146 if (nladdr.nl_pid != 0 ||
147 h->nlmsg_pid != rth->local.nl_pid ||
148 h->nlmsg_seq != rth->dump) {
149/* if (junk) {
150 err = junk(&nladdr, h, arg2);
151 if (err < 0)
152 return err;
153 } */
154 goto skip_it;
155 }
156
157 if (h->nlmsg_type == NLMSG_DONE) {
158 return 0;
159 }
160 if (h->nlmsg_type == NLMSG_ERROR) {
161 struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h);
162 if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
163 bb_error_msg("ERROR truncated");
164 } else {
165 errno = -l_err->error;
166 bb_perror_msg("RTNETLINK answers");
167 }
168 return -1;
169 }
170 err = filter(&nladdr, h, arg1);
171 if (err < 0)
172 return err;
173
174skip_it:
175 h = NLMSG_NEXT(h, status);
176 }
177 if (msg.msg_flags & MSG_TRUNC) {
178 bb_error_msg("message truncated");
179 continue;
180 }
181 if (status) {
182 bb_error_msg_and_die("remnant of size %d!", status);
183 }
184 }
185}
186
187int xrtnl_dump_filter(struct rtnl_handle *rth,
188 int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
189 void *arg1)
190{
191 int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/);
192 if (ret < 0)
193 bb_error_msg_and_die("dump terminated");
194 return ret;
195}
196
197int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
198 unsigned groups, struct nlmsghdr *answer,
199 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
200 void *jarg)
201{
202 int status;
203 unsigned seq;
204 struct nlmsghdr *h;
205 struct sockaddr_nl nladdr;
206 struct iovec iov = { (void*)n, n->nlmsg_len };
207 char buf[8192];
208 struct msghdr msg = {
209 (void*)&nladdr, sizeof(nladdr),
210 &iov, 1,
211 NULL, 0,
212 0
213 };
214
215 memset(&nladdr, 0, sizeof(nladdr));
216 nladdr.nl_family = AF_NETLINK;
217 nladdr.nl_pid = peer;
218 nladdr.nl_groups = groups;
219
220 n->nlmsg_seq = seq = ++rtnl->seq;
221 if (answer == NULL) {
222 n->nlmsg_flags |= NLM_F_ACK;
223 }
224 status = sendmsg(rtnl->fd, &msg, 0);
225
226 if (status < 0) {
227 bb_perror_msg("cannot talk to rtnetlink");
228 return -1;
229 }
230
231 iov.iov_base = buf;
232
233 while (1) {
234 iov.iov_len = sizeof(buf);
235 status = recvmsg(rtnl->fd, &msg, 0);
236
237 if (status < 0) {
238 if (errno == EINTR) {
239 continue;
240 }
241 bb_perror_msg("OVERRUN");
242 continue;
243 }
244 if (status == 0) {
245 bb_error_msg("EOF on netlink");
246 return -1;
247 }
248 if (msg.msg_namelen != sizeof(nladdr)) {
249 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen);
250 }
251 for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
252 int l_err;
253 int len = h->nlmsg_len;
254 int l = len - sizeof(*h);
255
256 if (l<0 || len>status) {
257 if (msg.msg_flags & MSG_TRUNC) {
258 bb_error_msg("truncated message");
259 return -1;
260 }
261 bb_error_msg_and_die("malformed message: len=%d!", len);
262 }
263
264 if (nladdr.nl_pid != peer ||
265 h->nlmsg_pid != rtnl->local.nl_pid ||
266 h->nlmsg_seq != seq) {
267 if (junk) {
268 l_err = junk(&nladdr, h, jarg);
269 if (l_err < 0) {
270 return l_err;
271 }
272 }
273 continue;
274 }
275
276 if (h->nlmsg_type == NLMSG_ERROR) {
277 struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
278 if (l < sizeof(struct nlmsgerr)) {
279 bb_error_msg("ERROR truncated");
280 } else {
281 errno = -err->error;
282 if (errno == 0) {
283 if (answer) {
284 memcpy(answer, h, h->nlmsg_len);
285 }
286 return 0;
287 }
288 bb_perror_msg("RTNETLINK answers");
289 }
290 return -1;
291 }
292 if (answer) {
293 memcpy(answer, h, h->nlmsg_len);
294 return 0;
295 }
296
297 bb_error_msg("unexpected reply!");
298
299 status -= NLMSG_ALIGN(len);
300 h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
301 }
302 if (msg.msg_flags & MSG_TRUNC) {
303 bb_error_msg("message truncated");
304 continue;
305 }
306 if (status) {
307 bb_error_msg_and_die("remnant of size %d!", status);
308 }
309 }
310}
311
312int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
313{
314 int len = RTA_LENGTH(4);
315 struct rtattr *rta;
316 if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen)
317 return -1;
318 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
319 rta->rta_type = type;
320 rta->rta_len = len;
321 memcpy(RTA_DATA(rta), &data, 4);
322 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
323 return 0;
324}
325
326int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
327{
328 int len = RTA_LENGTH(alen);
329 struct rtattr *rta;
330
331 if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen)
332 return -1;
333 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
334 rta->rta_type = type;
335 rta->rta_len = len;
336 memcpy(RTA_DATA(rta), data, alen);
337 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
338 return 0;
339}
340
341int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
342{
343 int len = RTA_LENGTH(4);
344 struct rtattr *subrta;
345
346 if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
347 return -1;
348 }
349 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
350 subrta->rta_type = type;
351 subrta->rta_len = len;
352 memcpy(RTA_DATA(subrta), &data, 4);
353 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
354 return 0;
355}
356
357int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
358{
359 struct rtattr *subrta;
360 int len = RTA_LENGTH(alen);
361
362 if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
363 return -1;
364 }
365 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
366 subrta->rta_type = type;
367 subrta->rta_len = len;
368 memcpy(RTA_DATA(subrta), data, alen);
369 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
370 return 0;
371}
372
373
374int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
375{
376 while (RTA_OK(rta, len)) {
377 if (rta->rta_type <= max) {
378 tb[rta->rta_type] = rta;
379 }
380 rta = RTA_NEXT(rta,len);
381 }
382 if (len) {
383 bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len);
384 }
385 return 0;
386}
Note: See TracBrowser for help on using the repository browser.