paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Common ioctl functions for Solaris. |
| 3 | * Copyright (C) 1997, 98 Kunihiro Ishiguro |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "linklist.h" |
| 26 | #include "if.h" |
| 27 | #include "prefix.h" |
| 28 | #include "ioctl.h" |
| 29 | #include "log.h" |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 30 | #include "privs.h" |
Donald Sharp | 4f84737 | 2015-12-22 15:24:25 -0500 | [diff] [blame] | 31 | #include "vty.h" |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 32 | |
| 33 | #include "zebra/rib.h" |
| 34 | #include "zebra/rt.h" |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 35 | #include "zebra/interface.h" |
David Lamparter | 285ed0c | 2015-09-15 02:46:53 -0700 | [diff] [blame] | 36 | #include "zebra/ioctl_solaris.h" |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 37 | |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 38 | extern struct zebra_privs_t zserv_privs; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 39 | |
| 40 | /* clear and set interface name string */ |
| 41 | void |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 42 | lifreq_set_name (struct lifreq *lifreq, const char *ifname) |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 43 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 44 | strncpy (lifreq->lifr_name, ifname, IFNAMSIZ); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* call ioctl system call */ |
| 48 | int |
| 49 | if_ioctl (u_long request, caddr_t buffer) |
| 50 | { |
| 51 | int sock; |
ajs | 4460e7a | 2005-01-29 17:07:40 +0000 | [diff] [blame] | 52 | int ret; |
| 53 | int err; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 54 | |
| 55 | if (zserv_privs.change(ZPRIVS_RAISE)) |
| 56 | zlog (NULL, LOG_ERR, "Can't raise privileges"); |
| 57 | |
| 58 | sock = socket (AF_INET, SOCK_DGRAM, 0); |
| 59 | if (sock < 0) |
| 60 | { |
ajs | 6a52d0d | 2005-01-30 18:49:28 +0000 | [diff] [blame] | 61 | int save_errno = errno; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 62 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 63 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
ajs | 6a52d0d | 2005-01-30 18:49:28 +0000 | [diff] [blame] | 64 | zlog_err("Cannot create UDP socket: %s", safe_strerror(save_errno)); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 65 | exit (1); |
| 66 | } |
| 67 | |
ajs | 4460e7a | 2005-01-29 17:07:40 +0000 | [diff] [blame] | 68 | if ((ret = ioctl (sock, request, buffer)) < 0) |
| 69 | err = errno; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 70 | |
| 71 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 72 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
| 73 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 74 | close (sock); |
| 75 | |
| 76 | if (ret < 0) |
| 77 | { |
| 78 | errno = err; |
| 79 | return ret; |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 84 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 85 | int |
| 86 | if_ioctl_ipv6 (u_long request, caddr_t buffer) |
| 87 | { |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 88 | #ifdef HAVE_IPV6 |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 89 | int sock; |
ajs | 4460e7a | 2005-01-29 17:07:40 +0000 | [diff] [blame] | 90 | int ret; |
| 91 | int err; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 92 | |
| 93 | if (zserv_privs.change(ZPRIVS_RAISE)) |
| 94 | zlog (NULL, LOG_ERR, "Can't raise privileges"); |
| 95 | |
| 96 | sock = socket (AF_INET6, SOCK_DGRAM, 0); |
| 97 | if (sock < 0) |
| 98 | { |
ajs | 6a52d0d | 2005-01-30 18:49:28 +0000 | [diff] [blame] | 99 | int save_errno = errno; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 100 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 101 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
ajs | 6a52d0d | 2005-01-30 18:49:28 +0000 | [diff] [blame] | 102 | zlog_err("Cannot create IPv6 datagram socket: %s", |
| 103 | safe_strerror(save_errno)); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 104 | exit (1); |
| 105 | } |
| 106 | |
ajs | 4460e7a | 2005-01-29 17:07:40 +0000 | [diff] [blame] | 107 | if ((ret = ioctl (sock, request, buffer)) < 0) |
| 108 | err = errno; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 109 | |
| 110 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 111 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
| 112 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 113 | close (sock); |
| 114 | |
| 115 | if (ret < 0) |
| 116 | { |
| 117 | errno = err; |
| 118 | return ret; |
| 119 | } |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 120 | #endif /* HAVE_IPV6 */ |
| 121 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 122 | return 0; |
| 123 | } |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * get interface metric |
| 127 | * -- if value is not avaliable set -1 |
| 128 | */ |
| 129 | void |
| 130 | if_get_metric (struct interface *ifp) |
| 131 | { |
| 132 | struct lifreq lifreq; |
| 133 | int ret; |
| 134 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 135 | lifreq_set_name (&lifreq, ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 136 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 137 | if (ifp->flags & IFF_IPV4) |
| 138 | ret = AF_IOCTL (AF_INET, SIOCGLIFMETRIC, (caddr_t) & lifreq); |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 139 | #ifdef SOLARIS_IPV6 |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 140 | else if (ifp->flags & IFF_IPV6) |
| 141 | ret = AF_IOCTL (AF_INET6, SIOCGLIFMETRIC, (caddr_t) & lifreq); |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 142 | #endif /* SOLARIS_IPV6 */ |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 143 | else |
| 144 | ret = -1; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 145 | |
| 146 | if (ret < 0) |
| 147 | return; |
| 148 | |
| 149 | ifp->metric = lifreq.lifr_metric; |
| 150 | |
| 151 | if (ifp->metric == 0) |
| 152 | ifp->metric = 1; |
| 153 | } |
| 154 | |
| 155 | /* get interface MTU */ |
| 156 | void |
| 157 | if_get_mtu (struct interface *ifp) |
| 158 | { |
| 159 | struct lifreq lifreq; |
| 160 | int ret; |
Paul Jakma | f5e004f | 2007-04-10 19:43:43 +0000 | [diff] [blame] | 161 | u_char changed = 0; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 162 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 163 | if (ifp->flags & IFF_IPV4) |
| 164 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 165 | lifreq_set_name (&lifreq, ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 166 | ret = AF_IOCTL (AF_INET, SIOCGLIFMTU, (caddr_t) & lifreq); |
| 167 | if (ret < 0) |
| 168 | { |
| 169 | zlog_info ("Can't lookup mtu on %s by ioctl(SIOCGLIFMTU)", |
| 170 | ifp->name); |
| 171 | ifp->mtu = -1; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | ifp->mtu = lifreq.lifr_metric; |
Paul Jakma | f5e004f | 2007-04-10 19:43:43 +0000 | [diff] [blame] | 176 | changed = 1; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 180 | #ifdef HAVE_IPV6 |
Denis Ovsienko | a13663a | 2007-08-21 16:12:40 +0000 | [diff] [blame] | 181 | if (ifp->flags & IFF_IPV6) |
| 182 | { |
| 183 | memset(&lifreq, 0, sizeof(lifreq)); |
| 184 | lifreq_set_name (&lifreq, ifp->name); |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 185 | |
Denis Ovsienko | a13663a | 2007-08-21 16:12:40 +0000 | [diff] [blame] | 186 | ret = AF_IOCTL (AF_INET6, SIOCGLIFMTU, (caddr_t) & lifreq); |
| 187 | if (ret < 0) |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 188 | { |
| 189 | zlog_info ("Can't lookup mtu6 on %s by ioctl(SIOCGIFMTU)", ifp->name); |
| 190 | ifp->mtu6 = -1; |
| 191 | } |
Denis Ovsienko | a13663a | 2007-08-21 16:12:40 +0000 | [diff] [blame] | 192 | else |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 193 | { |
| 194 | ifp->mtu6 = lifreq.lifr_metric; |
Paul Jakma | bd9da7f | 2007-04-29 16:50:46 +0000 | [diff] [blame] | 195 | changed = 1; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 196 | } |
Denis Ovsienko | a13663a | 2007-08-21 16:12:40 +0000 | [diff] [blame] | 197 | } |
| 198 | #endif /* HAVE_IPV6 */ |
| 199 | |
Paul Jakma | f5e004f | 2007-04-10 19:43:43 +0000 | [diff] [blame] | 200 | if (changed) |
| 201 | zebra_interface_up_update(ifp); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* Set up interface's address, netmask (and broadcast? ). |
| 205 | Solaris uses ifname:number semantics to set IP address aliases. */ |
| 206 | int |
| 207 | if_set_prefix (struct interface *ifp, struct connected *ifc) |
| 208 | { |
| 209 | int ret; |
| 210 | struct ifreq ifreq; |
| 211 | struct sockaddr_in addr; |
| 212 | struct sockaddr_in broad; |
| 213 | struct sockaddr_in mask; |
| 214 | struct prefix_ipv4 ifaddr; |
| 215 | struct prefix_ipv4 *p; |
| 216 | |
| 217 | p = (struct prefix_ipv4 *) ifc->address; |
| 218 | |
| 219 | ifaddr = *p; |
| 220 | |
| 221 | strncpy (ifreq.ifr_name, ifp->name, IFNAMSIZ); |
| 222 | |
| 223 | addr.sin_addr = p->prefix; |
| 224 | addr.sin_family = p->family; |
| 225 | memcpy (&ifreq.ifr_addr, &addr, sizeof (struct sockaddr_in)); |
| 226 | |
| 227 | ret = if_ioctl (SIOCSIFADDR, (caddr_t) & ifreq); |
| 228 | |
| 229 | if (ret < 0) |
| 230 | return ret; |
| 231 | |
| 232 | /* We need mask for make broadcast addr. */ |
| 233 | masklen2ip (p->prefixlen, &mask.sin_addr); |
| 234 | |
| 235 | if (if_is_broadcast (ifp)) |
| 236 | { |
| 237 | apply_mask_ipv4 (&ifaddr); |
| 238 | addr.sin_addr = ifaddr.prefix; |
| 239 | |
| 240 | broad.sin_addr.s_addr = (addr.sin_addr.s_addr | ~mask.sin_addr.s_addr); |
| 241 | broad.sin_family = p->family; |
| 242 | |
| 243 | memcpy (&ifreq.ifr_broadaddr, &broad, sizeof (struct sockaddr_in)); |
| 244 | ret = if_ioctl (SIOCSIFBRDADDR, (caddr_t) & ifreq); |
| 245 | if (ret < 0) |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 246 | return ret; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | mask.sin_family = p->family; |
| 250 | #ifdef SUNOS_5 |
| 251 | memcpy (&mask, &ifreq.ifr_addr, sizeof (mask)); |
| 252 | #else |
| 253 | memcpy (&ifreq.ifr_netmask, &mask, sizeof (struct sockaddr_in)); |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 254 | #endif /* SUNOS_5 */ |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 255 | ret = if_ioctl (SIOCSIFNETMASK, (caddr_t) & ifreq); |
| 256 | |
| 257 | return ((ret < 0) ? ret : 0); |
| 258 | } |
| 259 | |
| 260 | /* Set up interface's address, netmask (and broadcast). |
| 261 | Solaris uses ifname:number semantics to set IP address aliases. */ |
| 262 | int |
| 263 | if_unset_prefix (struct interface *ifp, struct connected *ifc) |
| 264 | { |
| 265 | int ret; |
| 266 | struct ifreq ifreq; |
| 267 | struct sockaddr_in addr; |
| 268 | struct prefix_ipv4 *p; |
| 269 | |
| 270 | p = (struct prefix_ipv4 *) ifc->address; |
| 271 | |
| 272 | strncpy (ifreq.ifr_name, ifp->name, IFNAMSIZ); |
| 273 | |
| 274 | memset (&addr, 0, sizeof (struct sockaddr_in)); |
| 275 | addr.sin_family = p->family; |
| 276 | memcpy (&ifreq.ifr_addr, &addr, sizeof (struct sockaddr_in)); |
| 277 | |
| 278 | ret = if_ioctl (SIOCSIFADDR, (caddr_t) & ifreq); |
| 279 | |
| 280 | if (ret < 0) |
| 281 | return ret; |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 286 | /* Get just the flags for the given name. |
| 287 | * Used by the normal 'if_get_flags' function, as well |
| 288 | * as the bootup interface-list code, which has to peek at per-address |
| 289 | * flags in order to figure out which ones should be ignored.. |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 290 | */ |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 291 | int |
| 292 | if_get_flags_direct (const char *ifname, uint64_t *flags, unsigned int af) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 293 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 294 | struct lifreq lifreq; |
| 295 | int ret; |
| 296 | |
| 297 | lifreq_set_name (&lifreq, ifname); |
| 298 | |
| 299 | ret = AF_IOCTL (af, SIOCGLIFFLAGS, (caddr_t) &lifreq); |
| 300 | |
| 301 | if (ret) |
| 302 | zlog_debug ("%s: ifname %s, error %s (%d)", |
| 303 | __func__, ifname, safe_strerror (errno), errno); |
| 304 | |
| 305 | *flags = lifreq.lifr_flags; |
| 306 | |
| 307 | return ret; |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 308 | } |
| 309 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 310 | /* get interface flags */ |
| 311 | void |
| 312 | if_get_flags (struct interface *ifp) |
| 313 | { |
David Lamparter | 6d93622 | 2015-09-15 02:59:04 -0700 | [diff] [blame] | 314 | int ret4 = 0, ret6 = 0; |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 315 | uint64_t newflags = 0; |
| 316 | uint64_t tmpflags; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 317 | |
| 318 | if (ifp->flags & IFF_IPV4) |
| 319 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 320 | ret4 = if_get_flags_direct (ifp->name, &tmpflags, AF_INET); |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 321 | |
| 322 | if (!ret4) |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 323 | newflags |= tmpflags; |
| 324 | else if (errno == ENXIO) |
| 325 | { |
| 326 | /* it's gone */ |
| 327 | UNSET_FLAG (ifp->flags, IFF_UP); |
| 328 | if_flags_update (ifp, ifp->flags); |
| 329 | } |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | if (ifp->flags & IFF_IPV6) |
| 333 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 334 | ret6 = if_get_flags_direct (ifp->name, &tmpflags, AF_INET6); |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 335 | |
| 336 | if (!ret6) |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 337 | newflags |= tmpflags; |
| 338 | else if (errno == ENXIO) |
| 339 | { |
| 340 | /* it's gone */ |
| 341 | UNSET_FLAG (ifp->flags, IFF_UP); |
| 342 | if_flags_update (ifp, ifp->flags); |
| 343 | } |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 344 | } |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 345 | |
| 346 | /* only update flags if one of above succeeded */ |
| 347 | if ( !(ret4 && ret6) ) |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 348 | if_flags_update (ifp, newflags); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Set interface flags */ |
| 352 | int |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 353 | if_set_flags (struct interface *ifp, uint64_t flags) |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 354 | { |
| 355 | int ret; |
| 356 | struct lifreq lifreq; |
| 357 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 358 | lifreq_set_name (&lifreq, ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 359 | |
| 360 | lifreq.lifr_flags = ifp->flags; |
| 361 | lifreq.lifr_flags |= flags; |
| 362 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 363 | if (ifp->flags & IFF_IPV4) |
| 364 | ret = AF_IOCTL (AF_INET, SIOCSLIFFLAGS, (caddr_t) & lifreq); |
| 365 | else if (ifp->flags & IFF_IPV6) |
| 366 | ret = AF_IOCTL (AF_INET6, SIOCSLIFFLAGS, (caddr_t) & lifreq); |
| 367 | else |
| 368 | ret = -1; |
| 369 | |
| 370 | if (ret < 0) |
| 371 | zlog_info ("can't set interface flags on %s: %s", ifp->name, |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 372 | safe_strerror (errno)); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 373 | else |
| 374 | ret = 0; |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 375 | |
| 376 | return ret; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* Unset interface's flag. */ |
| 380 | int |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 381 | if_unset_flags (struct interface *ifp, uint64_t flags) |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 382 | { |
| 383 | int ret; |
| 384 | struct lifreq lifreq; |
| 385 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 386 | lifreq_set_name (&lifreq, ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 387 | |
| 388 | lifreq.lifr_flags = ifp->flags; |
| 389 | lifreq.lifr_flags &= ~flags; |
| 390 | |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 391 | if (ifp->flags & IFF_IPV4) |
| 392 | ret = AF_IOCTL (AF_INET, SIOCSLIFFLAGS, (caddr_t) & lifreq); |
| 393 | else if (ifp->flags & IFF_IPV6) |
| 394 | ret = AF_IOCTL (AF_INET6, SIOCSLIFFLAGS, (caddr_t) & lifreq); |
| 395 | else |
| 396 | ret = -1; |
| 397 | |
| 398 | if (ret < 0) |
| 399 | zlog_info ("can't unset interface flags"); |
| 400 | else |
| 401 | ret = 0; |
| 402 | |
paul | 48a46fa | 2004-05-11 10:55:22 +0000 | [diff] [blame] | 403 | return ret; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | #ifdef HAVE_IPV6 |
| 407 | |
| 408 | /* Interface's address add/delete functions. */ |
| 409 | int |
| 410 | if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc) |
| 411 | { |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 412 | char addrbuf[PREFIX_STRLEN]; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 413 | |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 414 | zlog_warn ("Can't set %s on interface %s", |
Martin Winter | fe56125 | 2015-09-15 19:12:31 -0700 | [diff] [blame] | 415 | prefix2str(ifc->address, addrbuf, sizeof(addrbuf)), |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 416 | ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | |
| 420 | } |
| 421 | |
| 422 | int |
| 423 | if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc) |
| 424 | { |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 425 | char addrbuf[PREFIX_STRLEN]; |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 426 | |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 427 | zlog_warn ("Can't delete %s on interface %s", |
Martin Winter | fe56125 | 2015-09-15 19:12:31 -0700 | [diff] [blame] | 428 | prefix2str(ifc->address, addrbuf, sizeof(addrbuf)), |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 429 | ifp->name); |
paul | 8842468 | 2004-05-09 18:21:35 +0000 | [diff] [blame] | 430 | |
| 431 | return 0; |
| 432 | |
| 433 | } |
| 434 | |
| 435 | #endif /* HAVE_IPV6 */ |