paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Common ioctl functions. |
| 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 | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 30 | #include "privs.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | |
| 32 | #include "zebra/rib.h" |
| 33 | #include "zebra/rt.h" |
| 34 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 35 | extern struct zebra_privs_t zserv_privs; |
| 36 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | /* clear and set interface name string */ |
| 38 | void |
| 39 | ifreq_set_name (struct ifreq *ifreq, struct interface *ifp) |
| 40 | { |
| 41 | strncpy (ifreq->ifr_name, ifp->name, IFNAMSIZ); |
| 42 | } |
| 43 | |
| 44 | /* call ioctl system call */ |
| 45 | int |
| 46 | if_ioctl (u_long request, caddr_t buffer) |
| 47 | { |
| 48 | int sock; |
| 49 | int ret = 0; |
| 50 | int err = 0; |
| 51 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 52 | if (zserv_privs.change(ZPRIVS_RAISE)) |
| 53 | zlog (NULL, LOG_ERR, "Can't raise privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 54 | sock = socket (AF_INET, SOCK_DGRAM, 0); |
| 55 | if (sock < 0) |
| 56 | { |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 57 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 58 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | perror ("socket"); |
| 60 | exit (1); |
| 61 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | ret = ioctl (sock, request, buffer); |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 63 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 64 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | if (ret < 0) |
| 66 | { |
| 67 | err = errno; |
| 68 | } |
| 69 | close (sock); |
| 70 | |
| 71 | if (ret < 0) |
| 72 | { |
| 73 | errno = err; |
| 74 | return ret; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | #ifdef HAVE_IPV6 |
| 80 | int |
| 81 | if_ioctl_ipv6 (u_long request, caddr_t buffer) |
| 82 | { |
| 83 | int sock; |
| 84 | int ret = 0; |
| 85 | int err = 0; |
| 86 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 87 | if (zserv_privs.change(ZPRIVS_RAISE)) |
| 88 | zlog (NULL, LOG_ERR, "Can't raise privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 89 | sock = socket (AF_INET6, SOCK_DGRAM, 0); |
| 90 | if (sock < 0) |
| 91 | { |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 92 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 93 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 94 | perror ("socket"); |
| 95 | exit (1); |
| 96 | } |
| 97 | |
| 98 | ret = ioctl (sock, request, buffer); |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 99 | if (zserv_privs.change(ZPRIVS_LOWER)) |
| 100 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
| 101 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | if (ret < 0) |
| 103 | { |
| 104 | err = errno; |
| 105 | } |
| 106 | close (sock); |
| 107 | |
| 108 | if (ret < 0) |
| 109 | { |
| 110 | errno = err; |
| 111 | return ret; |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | #endif /* HAVE_IPV6 */ |
| 116 | |
| 117 | /* |
| 118 | * get interface metric |
| 119 | * -- if value is not avaliable set -1 |
| 120 | */ |
| 121 | void |
| 122 | if_get_metric (struct interface *ifp) |
| 123 | { |
| 124 | #ifdef SIOCGIFMETRIC |
| 125 | struct ifreq ifreq; |
| 126 | |
| 127 | ifreq_set_name (&ifreq, ifp); |
| 128 | |
| 129 | if (if_ioctl (SIOCGIFMETRIC, (caddr_t) &ifreq) < 0) |
| 130 | return; |
| 131 | ifp->metric = ifreq.ifr_metric; |
| 132 | if (ifp->metric == 0) |
| 133 | ifp->metric = 1; |
| 134 | #else /* SIOCGIFMETRIC */ |
| 135 | ifp->metric = -1; |
| 136 | #endif /* SIOCGIFMETRIC */ |
| 137 | } |
| 138 | |
| 139 | /* get interface MTU */ |
| 140 | void |
| 141 | if_get_mtu (struct interface *ifp) |
| 142 | { |
| 143 | struct ifreq ifreq; |
| 144 | |
| 145 | ifreq_set_name (&ifreq, ifp); |
| 146 | |
| 147 | #if defined(SIOCGIFMTU) |
| 148 | if (if_ioctl (SIOCGIFMTU, (caddr_t) & ifreq) < 0) |
| 149 | { |
| 150 | zlog_info ("Can't lookup mtu by ioctl(SIOCGIFMTU)"); |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 151 | ifp->mtu6 = ifp->mtu = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | return; |
| 153 | } |
| 154 | |
| 155 | #ifdef SUNOS_5 |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 156 | ifp->mtu6 = ifp->mtu = ifreq.ifr_metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | #else |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 158 | ifp->mtu6 = ifp->mtu = ifreq.ifr_mtu; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | #endif /* SUNOS_5 */ |
| 160 | |
| 161 | #else |
| 162 | zlog (NULL, LOG_INFO, "Can't lookup mtu on this system"); |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 163 | ifp->mtu6 = ifp->mtu = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 164 | #endif |
| 165 | } |
| 166 | |
| 167 | #ifdef HAVE_NETLINK |
| 168 | /* Interface address setting via netlink interface. */ |
| 169 | int |
| 170 | if_set_prefix (struct interface *ifp, struct connected *ifc) |
| 171 | { |
| 172 | return kernel_address_add_ipv4 (ifp, ifc); |
| 173 | } |
| 174 | |
| 175 | /* Interface address is removed using netlink interface. */ |
| 176 | int |
| 177 | if_unset_prefix (struct interface *ifp, struct connected *ifc) |
| 178 | { |
| 179 | return kernel_address_delete_ipv4 (ifp, ifc); |
| 180 | } |
| 181 | #else /* ! HAVE_NETLINK */ |
| 182 | #ifdef HAVE_IFALIASREQ |
| 183 | /* Set up interface's IP address, netmask (and broadcas? ). *BSD may |
| 184 | has ifaliasreq structure. */ |
| 185 | int |
| 186 | if_set_prefix (struct interface *ifp, struct connected *ifc) |
| 187 | { |
| 188 | int ret; |
| 189 | struct ifaliasreq addreq; |
| 190 | struct sockaddr_in addr; |
| 191 | struct sockaddr_in mask; |
| 192 | struct prefix_ipv4 *p; |
| 193 | |
| 194 | p = (struct prefix_ipv4 *) ifc->address; |
| 195 | |
| 196 | memset (&addreq, 0, sizeof addreq); |
| 197 | strncpy ((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name); |
| 198 | |
| 199 | memset (&addr, 0, sizeof (struct sockaddr_in)); |
| 200 | addr.sin_addr = p->prefix; |
| 201 | addr.sin_family = p->family; |
| 202 | #ifdef HAVE_SIN_LEN |
| 203 | addr.sin_len = sizeof (struct sockaddr_in); |
| 204 | #endif |
| 205 | memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in)); |
| 206 | |
| 207 | memset (&mask, 0, sizeof (struct sockaddr_in)); |
| 208 | masklen2ip (p->prefixlen, &mask.sin_addr); |
| 209 | mask.sin_family = p->family; |
| 210 | #ifdef HAVE_SIN_LEN |
| 211 | mask.sin_len = sizeof (struct sockaddr_in); |
| 212 | #endif |
| 213 | memcpy (&addreq.ifra_mask, &mask, sizeof (struct sockaddr_in)); |
| 214 | |
| 215 | ret = if_ioctl (SIOCAIFADDR, (caddr_t) &addreq); |
| 216 | if (ret < 0) |
| 217 | return ret; |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* Set up interface's IP address, netmask (and broadcas? ). *BSD may |
| 222 | has ifaliasreq structure. */ |
| 223 | int |
| 224 | if_unset_prefix (struct interface *ifp, struct connected *ifc) |
| 225 | { |
| 226 | int ret; |
| 227 | struct ifaliasreq addreq; |
| 228 | struct sockaddr_in addr; |
| 229 | struct sockaddr_in mask; |
| 230 | struct prefix_ipv4 *p; |
| 231 | |
| 232 | p = (struct prefix_ipv4 *)ifc->address; |
| 233 | |
| 234 | memset (&addreq, 0, sizeof addreq); |
| 235 | strncpy ((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name); |
| 236 | |
| 237 | memset (&addr, 0, sizeof (struct sockaddr_in)); |
| 238 | addr.sin_addr = p->prefix; |
| 239 | addr.sin_family = p->family; |
| 240 | #ifdef HAVE_SIN_LEN |
| 241 | addr.sin_len = sizeof (struct sockaddr_in); |
| 242 | #endif |
| 243 | memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in)); |
| 244 | |
| 245 | memset (&mask, 0, sizeof (struct sockaddr_in)); |
| 246 | masklen2ip (p->prefixlen, &mask.sin_addr); |
| 247 | mask.sin_family = p->family; |
| 248 | #ifdef HAVE_SIN_LEN |
| 249 | mask.sin_len = sizeof (struct sockaddr_in); |
| 250 | #endif |
| 251 | memcpy (&addreq.ifra_mask, &mask, sizeof (struct sockaddr_in)); |
| 252 | |
| 253 | ret = if_ioctl (SIOCDIFADDR, (caddr_t) &addreq); |
| 254 | if (ret < 0) |
| 255 | return ret; |
| 256 | return 0; |
| 257 | } |
| 258 | #else |
| 259 | /* Set up interface's address, netmask (and broadcas? ). Linux or |
| 260 | Solaris uses ifname:number semantics to set IP address aliases. */ |
| 261 | int |
| 262 | if_set_prefix (struct interface *ifp, struct connected *ifc) |
| 263 | { |
| 264 | int ret; |
| 265 | struct ifreq ifreq; |
| 266 | struct sockaddr_in addr; |
| 267 | struct sockaddr_in broad; |
| 268 | struct sockaddr_in mask; |
| 269 | struct prefix_ipv4 ifaddr; |
| 270 | struct prefix_ipv4 *p; |
| 271 | |
| 272 | p = (struct prefix_ipv4 *) ifc->address; |
| 273 | |
| 274 | ifaddr = *p; |
| 275 | |
| 276 | ifreq_set_name (&ifreq, ifp); |
| 277 | |
| 278 | addr.sin_addr = p->prefix; |
| 279 | addr.sin_family = p->family; |
| 280 | memcpy (&ifreq.ifr_addr, &addr, sizeof (struct sockaddr_in)); |
| 281 | ret = if_ioctl (SIOCSIFADDR, (caddr_t) &ifreq); |
| 282 | if (ret < 0) |
| 283 | return ret; |
| 284 | |
| 285 | /* We need mask for make broadcast addr. */ |
| 286 | masklen2ip (p->prefixlen, &mask.sin_addr); |
| 287 | |
| 288 | if (if_is_broadcast (ifp)) |
| 289 | { |
| 290 | apply_mask_ipv4 (&ifaddr); |
| 291 | addr.sin_addr = ifaddr.prefix; |
| 292 | |
| 293 | broad.sin_addr.s_addr = (addr.sin_addr.s_addr | ~mask.sin_addr.s_addr); |
| 294 | broad.sin_family = p->family; |
| 295 | |
| 296 | memcpy (&ifreq.ifr_broadaddr, &broad, sizeof (struct sockaddr_in)); |
| 297 | ret = if_ioctl (SIOCSIFBRDADDR, (caddr_t) &ifreq); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | mask.sin_family = p->family; |
| 303 | #ifdef SUNOS_5 |
| 304 | memcpy (&mask, &ifreq.ifr_addr, sizeof (mask)); |
| 305 | #else |
| 306 | memcpy (&ifreq.ifr_netmask, &mask, sizeof (struct sockaddr_in)); |
| 307 | #endif /* SUNOS5 */ |
| 308 | ret = if_ioctl (SIOCSIFNETMASK, (caddr_t) &ifreq); |
| 309 | if (ret < 0) |
| 310 | return ret; |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /* Set up interface's address, netmask (and broadcas? ). Linux or |
| 316 | Solaris uses ifname:number semantics to set IP address aliases. */ |
| 317 | int |
| 318 | if_unset_prefix (struct interface *ifp, struct connected *ifc) |
| 319 | { |
| 320 | int ret; |
| 321 | struct ifreq ifreq; |
| 322 | struct sockaddr_in addr; |
| 323 | struct prefix_ipv4 *p; |
| 324 | |
| 325 | p = (struct prefix_ipv4 *) ifc->address; |
| 326 | |
| 327 | ifreq_set_name (&ifreq, ifp); |
| 328 | |
| 329 | memset (&addr, 0, sizeof (struct sockaddr_in)); |
| 330 | addr.sin_family = p->family; |
| 331 | memcpy (&ifreq.ifr_addr, &addr, sizeof (struct sockaddr_in)); |
| 332 | ret = if_ioctl (SIOCSIFADDR, (caddr_t) &ifreq); |
| 333 | if (ret < 0) |
| 334 | return ret; |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | #endif /* HAVE_IFALIASREQ */ |
| 339 | #endif /* HAVE_NETLINK */ |
| 340 | |
| 341 | /* get interface flags */ |
| 342 | void |
| 343 | if_get_flags (struct interface *ifp) |
| 344 | { |
| 345 | int ret; |
| 346 | struct ifreq ifreq; |
| 347 | |
| 348 | ifreq_set_name (&ifreq, ifp); |
| 349 | |
| 350 | ret = if_ioctl (SIOCGIFFLAGS, (caddr_t) &ifreq); |
| 351 | if (ret < 0) |
| 352 | { |
| 353 | perror ("ioctl"); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | ifp->flags = ifreq.ifr_flags & 0x0000ffff; |
| 358 | } |
| 359 | |
| 360 | /* Set interface flags */ |
| 361 | int |
| 362 | if_set_flags (struct interface *ifp, unsigned long flags) |
| 363 | { |
| 364 | int ret; |
| 365 | struct ifreq ifreq; |
| 366 | |
paul | d1724b6 | 2003-10-22 02:41:52 +0000 | [diff] [blame] | 367 | memset (&ifreq, 0, sizeof(struct ifreq)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | ifreq_set_name (&ifreq, ifp); |
| 369 | |
| 370 | ifreq.ifr_flags = ifp->flags; |
| 371 | ifreq.ifr_flags |= flags; |
| 372 | |
| 373 | ret = if_ioctl (SIOCSIFFLAGS, (caddr_t) &ifreq); |
| 374 | |
| 375 | if (ret < 0) |
| 376 | { |
| 377 | zlog_info ("can't set interface flags"); |
| 378 | return ret; |
| 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | /* Unset interface's flag. */ |
| 384 | int |
| 385 | if_unset_flags (struct interface *ifp, unsigned long flags) |
| 386 | { |
| 387 | int ret; |
| 388 | struct ifreq ifreq; |
| 389 | |
paul | d1724b6 | 2003-10-22 02:41:52 +0000 | [diff] [blame] | 390 | memset (&ifreq, 0, sizeof(struct ifreq)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | ifreq_set_name (&ifreq, ifp); |
| 392 | |
| 393 | ifreq.ifr_flags = ifp->flags; |
| 394 | ifreq.ifr_flags &= ~flags; |
| 395 | |
| 396 | ret = if_ioctl (SIOCSIFFLAGS, (caddr_t) &ifreq); |
| 397 | |
| 398 | if (ret < 0) |
| 399 | { |
| 400 | zlog_info ("can't unset interface flags"); |
| 401 | return ret; |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | #ifdef HAVE_IPV6 |
| 407 | |
| 408 | #ifdef LINUX_IPV6 |
| 409 | #ifndef _LINUX_IN6_H |
| 410 | /* linux/include/net/ipv6.h */ |
| 411 | struct in6_ifreq |
| 412 | { |
| 413 | struct in6_addr ifr6_addr; |
| 414 | u_int32_t ifr6_prefixlen; |
| 415 | int ifr6_ifindex; |
| 416 | }; |
| 417 | #endif /* _LINUX_IN6_H */ |
| 418 | |
| 419 | /* Interface's address add/delete functions. */ |
| 420 | int |
| 421 | if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc) |
| 422 | { |
| 423 | int ret; |
| 424 | struct prefix_ipv6 *p; |
| 425 | struct in6_ifreq ifreq; |
| 426 | |
| 427 | p = (struct prefix_ipv6 *) ifc->address; |
| 428 | |
| 429 | memset (&ifreq, 0, sizeof (struct in6_ifreq)); |
| 430 | |
| 431 | memcpy (&ifreq.ifr6_addr, &p->prefix, sizeof (struct in6_addr)); |
| 432 | ifreq.ifr6_ifindex = ifp->ifindex; |
| 433 | ifreq.ifr6_prefixlen = p->prefixlen; |
| 434 | |
| 435 | ret = if_ioctl_ipv6 (SIOCSIFADDR, (caddr_t) &ifreq); |
| 436 | |
| 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | int |
| 441 | if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc) |
| 442 | { |
| 443 | int ret; |
| 444 | struct prefix_ipv6 *p; |
| 445 | struct in6_ifreq ifreq; |
| 446 | |
| 447 | p = (struct prefix_ipv6 *) ifc->address; |
| 448 | |
| 449 | memset (&ifreq, 0, sizeof (struct in6_ifreq)); |
| 450 | |
| 451 | memcpy (&ifreq.ifr6_addr, &p->prefix, sizeof (struct in6_addr)); |
| 452 | ifreq.ifr6_ifindex = ifp->ifindex; |
| 453 | ifreq.ifr6_prefixlen = p->prefixlen; |
| 454 | |
| 455 | ret = if_ioctl_ipv6 (SIOCDIFADDR, (caddr_t) &ifreq); |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | #else /* LINUX_IPV6 */ |
| 460 | #ifdef HAVE_IN6_ALIASREQ |
| 461 | #ifndef ND6_INFINITE_LIFETIME |
| 462 | #define ND6_INFINITE_LIFETIME 0xffffffffL |
| 463 | #endif /* ND6_INFINITE_LIFETIME */ |
| 464 | int |
| 465 | if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc) |
| 466 | { |
| 467 | int ret; |
| 468 | struct in6_aliasreq addreq; |
| 469 | struct sockaddr_in6 addr; |
| 470 | struct sockaddr_in6 mask; |
| 471 | struct prefix_ipv6 *p; |
| 472 | |
| 473 | p = (struct prefix_ipv6 * ) ifc->address; |
| 474 | |
| 475 | memset (&addreq, 0, sizeof addreq); |
| 476 | strncpy ((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name); |
| 477 | |
| 478 | memset (&addr, 0, sizeof (struct sockaddr_in6)); |
| 479 | addr.sin6_addr = p->prefix; |
| 480 | addr.sin6_family = p->family; |
| 481 | #ifdef HAVE_SIN_LEN |
| 482 | addr.sin6_len = sizeof (struct sockaddr_in6); |
| 483 | #endif |
| 484 | memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in6)); |
| 485 | |
| 486 | memset (&mask, 0, sizeof (struct sockaddr_in6)); |
| 487 | masklen2ip6 (p->prefixlen, &mask.sin6_addr); |
| 488 | mask.sin6_family = p->family; |
| 489 | #ifdef HAVE_SIN_LEN |
| 490 | mask.sin6_len = sizeof (struct sockaddr_in6); |
| 491 | #endif |
| 492 | memcpy (&addreq.ifra_prefixmask, &mask, sizeof (struct sockaddr_in6)); |
paul | 0e4f190 | 2003-06-12 02:13:45 +0000 | [diff] [blame] | 493 | |
| 494 | addreq.ifra_lifetime.ia6t_vltime = 0xffffffff; |
| 495 | addreq.ifra_lifetime.ia6t_pltime = 0xffffffff; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 496 | |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 497 | #ifdef HAVE_IFRA_LIFETIME |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 498 | addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; |
| 499 | addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 500 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | |
| 502 | ret = if_ioctl_ipv6 (SIOCAIFADDR_IN6, (caddr_t) &addreq); |
| 503 | if (ret < 0) |
| 504 | return ret; |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | int |
| 509 | if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc) |
| 510 | { |
| 511 | int ret; |
| 512 | struct in6_aliasreq addreq; |
| 513 | struct sockaddr_in6 addr; |
| 514 | struct sockaddr_in6 mask; |
| 515 | struct prefix_ipv6 *p; |
| 516 | |
| 517 | p = (struct prefix_ipv6 *) ifc->address; |
| 518 | |
| 519 | memset (&addreq, 0, sizeof addreq); |
| 520 | strncpy ((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name); |
| 521 | |
| 522 | memset (&addr, 0, sizeof (struct sockaddr_in6)); |
| 523 | addr.sin6_addr = p->prefix; |
| 524 | addr.sin6_family = p->family; |
| 525 | #ifdef HAVE_SIN_LEN |
| 526 | addr.sin6_len = sizeof (struct sockaddr_in6); |
| 527 | #endif |
| 528 | memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in6)); |
| 529 | |
| 530 | memset (&mask, 0, sizeof (struct sockaddr_in6)); |
| 531 | masklen2ip6 (p->prefixlen, &mask.sin6_addr); |
| 532 | mask.sin6_family = p->family; |
| 533 | #ifdef HAVE_SIN_LEN |
| 534 | mask.sin6_len = sizeof (struct sockaddr_in6); |
| 535 | #endif |
| 536 | memcpy (&addreq.ifra_prefixmask, &mask, sizeof (struct sockaddr_in6)); |
| 537 | |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 538 | #ifdef HAVE_IFRA_LIFETIME |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; |
| 540 | addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 541 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 542 | |
| 543 | ret = if_ioctl_ipv6 (SIOCDIFADDR_IN6, (caddr_t) &addreq); |
| 544 | if (ret < 0) |
| 545 | return ret; |
| 546 | return 0; |
| 547 | } |
| 548 | #else |
| 549 | int |
| 550 | if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc) |
| 551 | { |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | int |
| 556 | if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc) |
| 557 | { |
| 558 | return 0; |
| 559 | } |
| 560 | #endif /* HAVE_IN6_ALIASREQ */ |
| 561 | |
| 562 | #endif /* LINUX_IPV6 */ |
| 563 | |
| 564 | #endif /* HAVE_IPV6 */ |