~ubuntu-branches/ubuntu/lucid/bind9/lucid

« back to all changes in this revision

Viewing changes to lib/isc/unix/interfaceiter.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, Internet Software Consortium, Inc, InterNIC, LaMont Jones
  • Date: 2009-07-28 22:03:14 UTC
  • mfrom: (1.6.1 upstream) (10.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090728220314-9wztcj047dxvvhdh
Tags: 1:9.6.1.dfsg.P1-1
[Internet Software Consortium, Inc]

* A specially crafted update packet will cause named to exit. 
  CVE-2009-0696, CERT VU#725188.  Closes: #538975

[InterNIC]

* Update db.root hints file.

[LaMont Jones]

* Move default zone definitions from named.conf to named.conf.default-zones.
   Closes: #492308
* use start-stop-daemon if rndc stop fails.  Closes: #536487
* lwresd: pidfile name was wrong in init script.  Closes: #527137

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
 
2
 * Copyright (C) 2004, 2005, 2007-2009  Internet Systems Consortium, Inc. ("ISC")
3
3
 * Copyright (C) 1999-2003  Internet Software Consortium.
4
4
 *
5
5
 * Permission to use, copy, modify, and/or distribute this software for any
15
15
 * PERFORMANCE OF THIS SOFTWARE.
16
16
 */
17
17
 
18
 
/* $Id: interfaceiter.c,v 1.42 2007/06/19 23:47:18 tbox Exp $ */
 
18
/* $Id: interfaceiter.c,v 1.44.120.2 2009/02/16 23:47:15 tbox Exp $ */
19
19
 
20
20
/*! \file */
21
21
 
145
145
 * Include system-dependent code.
146
146
 */
147
147
 
 
148
#ifdef __linux
 
149
#define ISC_IF_INET6_SZ \
 
150
    sizeof("00000000000000000000000000000001 01 80 10 80 XXXXXXloXXXXXXXX\n")
 
151
static isc_result_t linux_if_inet6_next(isc_interfaceiter_t *);
 
152
static isc_result_t linux_if_inet6_current(isc_interfaceiter_t *);
 
153
static void linux_if_inet6_first(isc_interfaceiter_t *iter);
 
154
#endif
 
155
 
148
156
#if HAVE_GETIFADDRS
149
157
#include "ifiter_getifaddrs.c"
150
158
#elif HAVE_IFLIST_SYSCTL
153
161
#include "ifiter_ioctl.c"
154
162
#endif
155
163
 
 
164
#ifdef __linux
 
165
static void
 
166
linux_if_inet6_first(isc_interfaceiter_t *iter) {
 
167
        if (iter->proc != NULL) {
 
168
                rewind(iter->proc);
 
169
                (void)linux_if_inet6_next(iter);
 
170
        } else
 
171
                iter->valid = ISC_R_NOMORE;
 
172
}
 
173
 
 
174
static isc_result_t
 
175
linux_if_inet6_next(isc_interfaceiter_t *iter) {
 
176
        if (iter->proc != NULL &&
 
177
            fgets(iter->entry, sizeof(iter->entry), iter->proc) != NULL)
 
178
                iter->valid = ISC_R_SUCCESS;
 
179
        else
 
180
                iter->valid = ISC_R_NOMORE;
 
181
        return (iter->valid);
 
182
}
 
183
 
 
184
static isc_result_t
 
185
linux_if_inet6_current(isc_interfaceiter_t *iter) {
 
186
        char address[33];
 
187
        char name[IF_NAMESIZE+1];
 
188
        struct in6_addr addr6;
 
189
        int ifindex, prefix, flag3, flag4;
 
190
        int res;
 
191
        unsigned int i;
 
192
 
 
193
        if (iter->valid != ISC_R_SUCCESS)
 
194
                return (iter->valid);
 
195
        if (iter->proc == NULL) {
 
196
                isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
 
197
                              ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
 
198
                              "/proc/net/if_inet6:iter->proc == NULL");
 
199
                return (ISC_R_FAILURE);
 
200
        }
 
201
 
 
202
        res = sscanf(iter->entry, "%32[a-f0-9] %x %x %x %x %16s\n",
 
203
                     address, &ifindex, &prefix, &flag3, &flag4, name);
 
204
        if (res != 6) {
 
205
                isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
 
206
                              ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
 
207
                              "/proc/net/if_inet6:sscanf() -> %d (expected 6)",
 
208
                              res);
 
209
                return (ISC_R_FAILURE);
 
210
        }
 
211
        if (strlen(address) != 32) {
 
212
                isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
 
213
                              ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
 
214
                              "/proc/net/if_inet6:strlen(%s) != 32", address);
 
215
                return (ISC_R_FAILURE);
 
216
        }
 
217
        for (i = 0; i < 16; i++) {
 
218
                unsigned char byte;
 
219
                static const char hex[] = "0123456789abcdef";
 
220
                byte = ((strchr(hex, address[i * 2]) - hex) << 4) |
 
221
                       (strchr(hex, address[i * 2 + 1]) - hex);
 
222
                addr6.s6_addr[i] = byte;
 
223
        }
 
224
        iter->current.af = AF_INET6;
 
225
        iter->current.flags = INTERFACE_F_UP;
 
226
        isc_netaddr_fromin6(&iter->current.address, &addr6);
 
227
        if (isc_netaddr_islinklocal(&iter->current.address)) {
 
228
                isc_netaddr_setzone(&iter->current.address,
 
229
                                    (isc_uint32_t)ifindex);
 
230
        }
 
231
        for (i = 0; i < 16; i++) {
 
232
                if (prefix > 8) {
 
233
                        addr6.s6_addr[i] = 0xff;
 
234
                        prefix -= 8;
 
235
                } else {
 
236
                        addr6.s6_addr[i] = (0xff << (8 - prefix)) & 0xff;
 
237
                        prefix = 0;
 
238
                }
 
239
        }
 
240
        isc_netaddr_fromin6(&iter->current.netmask, &addr6);
 
241
        strncpy(iter->current.name, name, sizeof(iter->current.name));
 
242
        return (ISC_R_SUCCESS);
 
243
}
 
244
#endif
 
245
 
156
246
/*
157
247
 * The remaining code is common to the sysctl and ioctl case.
158
248
 */