| @@ -1,16 +1,16 @@ | | | @@ -1,16 +1,16 @@ |
1 | /* $NetBSD: ifwatchd.c,v 1.41 2016/10/07 15:49:58 christos Exp $ */ | | 1 | /* $NetBSD: ifwatchd.c,v 1.42 2017/04/11 14:21:35 roy Exp $ */ |
2 | #include <sys/cdefs.h> | | 2 | #include <sys/cdefs.h> |
3 | __RCSID("$NetBSD: ifwatchd.c,v 1.41 2016/10/07 15:49:58 christos Exp $"); | | 3 | __RCSID("$NetBSD: ifwatchd.c,v 1.42 2017/04/11 14:21:35 roy Exp $"); |
4 | | | 4 | |
5 | /*- | | 5 | /*- |
6 | * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. | | 6 | * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * This code is derived from software contributed to The NetBSD Foundation | | 9 | * This code is derived from software contributed to The NetBSD Foundation |
10 | * by Martin Husemann <martin@NetBSD.org>. | | 10 | * by Martin Husemann <martin@NetBSD.org>. |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
15 | * 1. Redistributions of source code must retain the above copyright | | 15 | * 1. Redistributions of source code must retain the above copyright |
16 | * notice, this list of conditions and the following disclaimer. | | 16 | * notice, this list of conditions and the following disclaimer. |
| @@ -98,26 +98,30 @@ struct interface_data { | | | @@ -98,26 +98,30 @@ struct interface_data { |
98 | int last_carrier_status; | | 98 | int last_carrier_status; |
99 | char * ifname; | | 99 | char * ifname; |
100 | }; | | 100 | }; |
101 | static SLIST_HEAD(,interface_data) ifs = SLIST_HEAD_INITIALIZER(ifs); | | 101 | static SLIST_HEAD(,interface_data) ifs = SLIST_HEAD_INITIALIZER(ifs); |
102 | | | 102 | |
103 | int | | 103 | int |
104 | main(int argc, char **argv) | | 104 | main(int argc, char **argv) |
105 | { | | 105 | { |
106 | int c, s, n; | | 106 | int c, s, n; |
107 | int errs = 0; | | 107 | int errs = 0; |
108 | struct msghdr msg; | | 108 | struct msghdr msg; |
109 | struct iovec iov[1]; | | 109 | struct iovec iov[1]; |
110 | char buf[2048]; | | 110 | char buf[2048]; |
| | | 111 | unsigned char msgfilter[] = { |
| | | 112 | RTM_IFINFO, RTM_IFANNOUNCE, |
| | | 113 | RTM_NEWADDR, RTM_DELADDR, |
| | | 114 | }; |
111 | | | 115 | |
112 | openlog(argv[0], LOG_PID|LOG_CONS, LOG_DAEMON); | | 116 | openlog(argv[0], LOG_PID|LOG_CONS, LOG_DAEMON); |
113 | while ((c = getopt(argc, argv, "qvhic:n:u:d:A:D:")) != -1) { | | 117 | while ((c = getopt(argc, argv, "qvhic:n:u:d:A:D:")) != -1) { |
114 | switch (c) { | | 118 | switch (c) { |
115 | case 'h': | | 119 | case 'h': |
116 | usage(); | | 120 | usage(); |
117 | return 0; | | 121 | return 0; |
118 | | | 122 | |
119 | case 'i': | | 123 | case 'i': |
120 | inhibit_initial = 1; | | 124 | inhibit_initial = 1; |
121 | break; | | 125 | break; |
122 | | | 126 | |
123 | case 'v': | | 127 | case 'v': |
| @@ -181,26 +185,29 @@ main(int argc, char **argv) | | | @@ -181,26 +185,29 @@ main(int argc, char **argv) |
181 | list_interfaces(argv[0]); | | 185 | list_interfaces(argv[0]); |
182 | argv++; | | 186 | argv++; |
183 | argc--; | | 187 | argc--; |
184 | } | | 188 | } |
185 | | | 189 | |
186 | if (!verbose) | | 190 | if (!verbose) |
187 | daemon(0, 0); | | 191 | daemon(0, 0); |
188 | | | 192 | |
189 | s = socket(PF_ROUTE, SOCK_RAW, 0); | | 193 | s = socket(PF_ROUTE, SOCK_RAW, 0); |
190 | if (s < 0) { | | 194 | if (s < 0) { |
191 | syslog(LOG_ERR, "error opening routing socket: %m"); | | 195 | syslog(LOG_ERR, "error opening routing socket: %m"); |
192 | exit(EXIT_FAILURE); | | 196 | exit(EXIT_FAILURE); |
193 | } | | 197 | } |
| | | 198 | if (setsockopt(s, PF_ROUTE, RO_MSGFILTER, |
| | | 199 | &msgfilter, sizeof(msgfilter)) < 0) |
| | | 200 | syslog(LOG_ERR, "RO_MSGFILTER: %m"); |
194 | | | 201 | |
195 | if (!inhibit_initial) | | 202 | if (!inhibit_initial) |
196 | run_initial_ups(); | | 203 | run_initial_ups(); |
197 | | | 204 | |
198 | iov[0].iov_base = buf; | | 205 | iov[0].iov_base = buf; |
199 | iov[0].iov_len = sizeof(buf); | | 206 | iov[0].iov_len = sizeof(buf); |
200 | memset(&msg, 0, sizeof(msg)); | | 207 | memset(&msg, 0, sizeof(msg)); |
201 | msg.msg_iov = iov; | | 208 | msg.msg_iov = iov; |
202 | msg.msg_iovlen = 1; | | 209 | msg.msg_iovlen = 1; |
203 | | | 210 | |
204 | for (;;) { | | 211 | for (;;) { |
205 | n = recvmsg(s, &msg, 0); | | 212 | n = recvmsg(s, &msg, 0); |
206 | if (n == -1) { | | 213 | if (n == -1) { |