in6_ifattach.c (192895) | in6_ifattach.c (193066) |
---|---|
1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: in6_ifattach.c,v 1.118 2001/05/24 07:44:00 itojun Exp $ 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: in6_ifattach.c,v 1.118 2001/05/24 07:44:00 itojun Exp $ 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/netinet6/in6_ifattach.c 192895 2009-05-27 14:11:23Z jamie $"); | 33__FBSDID("$FreeBSD: head/sys/netinet6/in6_ifattach.c 193066 2009-05-29 21:27:12Z jamie $"); |
34 35#include "opt_route.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/malloc.h> 40#include <sys/socket.h> 41#include <sys/sockio.h> | 34 35#include "opt_route.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/malloc.h> 40#include <sys/socket.h> 41#include <sys/sockio.h> |
42#include <sys/jail.h> |
|
42#include <sys/kernel.h> 43#include <sys/syslog.h> 44#include <sys/md5.h> 45#include <sys/vimage.h> 46 47#include <net/if.h> 48#include <net/if_dl.h> 49#include <net/if_types.h> --- 49 unchanged lines hidden (view full) --- 99 * (1) random enough and (2) does not change across reboot. 100 * We currently use MD5(hostname) for it. 101 * 102 * in6 - upper 64bits are preserved 103 */ 104static int 105get_rand_ifid(struct ifnet *ifp, struct in6_addr *in6) 106{ | 43#include <sys/kernel.h> 44#include <sys/syslog.h> 45#include <sys/md5.h> 46#include <sys/vimage.h> 47 48#include <net/if.h> 49#include <net/if_dl.h> 50#include <net/if_types.h> --- 49 unchanged lines hidden (view full) --- 100 * (1) random enough and (2) does not change across reboot. 101 * We currently use MD5(hostname) for it. 102 * 103 * in6 - upper 64bits are preserved 104 */ 105static int 106get_rand_ifid(struct ifnet *ifp, struct in6_addr *in6) 107{ |
107 INIT_VPROCG(TD_TO_VPROCG(curthread)); /* XXX V_hostname needs this */ | |
108 MD5_CTX ctxt; | 108 MD5_CTX ctxt; |
109 struct prison *pr; |
|
109 u_int8_t digest[16]; 110 int hostnamelen; 111 | 110 u_int8_t digest[16]; 111 int hostnamelen; 112 |
112 mtx_lock(&hostname_mtx); 113 hostnamelen = strlen(V_hostname); | 113 pr = curthread->td_ucred->cr_prison; 114 mtx_lock(&pr->pr_mtx); 115 hostnamelen = strlen(pr->pr_host); |
114#if 0 115 /* we need at least several letters as seed for ifid */ | 116#if 0 117 /* we need at least several letters as seed for ifid */ |
116 if (hostnamelen < 3) | 118 if (hostnamelen < 3) { 119 mtx_unlock(&pr->pr_mtx); |
117 return -1; | 120 return -1; |
121 } |
|
118#endif 119 120 /* generate 8 bytes of pseudo-random value. */ 121 bzero(&ctxt, sizeof(ctxt)); 122 MD5Init(&ctxt); | 122#endif 123 124 /* generate 8 bytes of pseudo-random value. */ 125 bzero(&ctxt, sizeof(ctxt)); 126 MD5Init(&ctxt); |
123 MD5Update(&ctxt, V_hostname, hostnamelen); 124 mtx_unlock(&hostname_mtx); | 127 MD5Update(&ctxt, pr->pr_host, hostnamelen); 128 mtx_unlock(&pr->pr_mtx); |
125 MD5Final(digest, &ctxt); 126 127 /* assumes sizeof(digest) > sizeof(ifid) */ 128 bcopy(digest, &in6->s6_addr[8], 8); 129 130 /* make sure to set "u" bit to local, and "g" bit to individual. */ 131 in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */ 132 in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */ --- 482 unchanged lines hidden (view full) --- 615 * see draft-ietf-ipngwg-icmp-name-lookup-* (04 and later). 616 * 617 * when ifp == NULL, the caller is responsible for filling scopeid. 618 */ 619int 620in6_nigroup(struct ifnet *ifp, const char *name, int namelen, 621 struct in6_addr *in6) 622{ | 129 MD5Final(digest, &ctxt); 130 131 /* assumes sizeof(digest) > sizeof(ifid) */ 132 bcopy(digest, &in6->s6_addr[8], 8); 133 134 /* make sure to set "u" bit to local, and "g" bit to individual. */ 135 in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */ 136 in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */ --- 482 unchanged lines hidden (view full) --- 619 * see draft-ietf-ipngwg-icmp-name-lookup-* (04 and later). 620 * 621 * when ifp == NULL, the caller is responsible for filling scopeid. 622 */ 623int 624in6_nigroup(struct ifnet *ifp, const char *name, int namelen, 625 struct in6_addr *in6) 626{ |
623 INIT_VPROCG(TD_TO_VPROCG(curthread)); /* XXX V_hostname needs this */ | 627 struct prison *pr; |
624 const char *p; 625 u_char *q; 626 MD5_CTX ctxt; | 628 const char *p; 629 u_char *q; 630 MD5_CTX ctxt; |
627 int use_hostname; | |
628 u_int8_t digest[16]; 629 char l; 630 char n[64]; /* a single label must not exceed 63 chars */ 631 632 /* 633 * If no name is given and namelen is -1, 634 * we try to do the hostname lookup ourselves. 635 */ 636 if (!name && namelen == -1) { | 631 u_int8_t digest[16]; 632 char l; 633 char n[64]; /* a single label must not exceed 63 chars */ 634 635 /* 636 * If no name is given and namelen is -1, 637 * we try to do the hostname lookup ourselves. 638 */ 639 if (!name && namelen == -1) { |
637 use_hostname = 1; 638 mtx_lock(&hostname_mtx); 639 name = V_hostname; | 640 pr = curthread->td_ucred->cr_prison; 641 mtx_lock(&pr->pr_mtx); 642 name = pr->pr_host; |
640 namelen = strlen(name); 641 } else | 643 namelen = strlen(name); 644 } else |
642 use_hostname = 0; | 645 pr = NULL; |
643 if (!name || !namelen) { | 646 if (!name || !namelen) { |
644 if (use_hostname) 645 mtx_unlock(&hostname_mtx); | 647 if (pr != NULL) 648 mtx_unlock(&pr->pr_mtx); |
646 return -1; 647 } 648 649 p = name; 650 while (p && *p && *p != '.' && p - name < namelen) 651 p++; 652 if (p == name || p - name > sizeof(n) - 1) { | 649 return -1; 650 } 651 652 p = name; 653 while (p && *p && *p != '.' && p - name < namelen) 654 p++; 655 if (p == name || p - name > sizeof(n) - 1) { |
653 if (use_hostname) 654 mtx_unlock(&hostname_mtx); | 656 if (pr != NULL) 657 mtx_unlock(&pr->pr_mtx); |
655 return -1; /* label too long */ 656 } 657 l = p - name; 658 strncpy(n, name, l); | 658 return -1; /* label too long */ 659 } 660 l = p - name; 661 strncpy(n, name, l); |
659 if (use_hostname) 660 mtx_unlock(&hostname_mtx); | 662 if (pr != NULL) 663 mtx_unlock(&pr->pr_mtx); |
661 n[(int)l] = '\0'; 662 for (q = n; *q; q++) { 663 if ('A' <= *q && *q <= 'Z') 664 *q = *q - 'A' + 'a'; 665 } 666 667 /* generate 8 bytes of pseudo-random value. */ 668 bzero(&ctxt, sizeof(ctxt)); --- 307 unchanged lines hidden --- | 664 n[(int)l] = '\0'; 665 for (q = n; *q; q++) { 666 if ('A' <= *q && *q <= 'Z') 667 *q = *q - 'A' + 'a'; 668 } 669 670 /* generate 8 bytes of pseudo-random value. */ 671 bzero(&ctxt, sizeof(ctxt)); --- 307 unchanged lines hidden --- |