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