summaryrefslogtreecommitdiffstats
path: root/contrib/bind/bin/named/ns_udp.c
blob: 8b1af5e90df4251586deec53ec746d45ebaa7869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "$Id: ns_udp.c,v 8.5 1997/05/21 19:52:26 halley Exp $";
#endif /* not lint */

/*
 * Copyright (c) 1996, 1997 by Internet Software Consortium.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#include "port_before.h"

#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/file.h>

#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>

#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <nlist.h>
#include <resolv.h>
#include <stdio.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>

#include <isc/eventlib.h>
#include <isc/logging.h>

#include "port_after.h"

#include "named.h"

void
ns_udp() {
#if defined(CHECK_UDP_SUM) || defined(FIX_UDP_SUM)
	struct nlist nl[2];
	int fd;
	int sum;
	u_long res, offset;

	nl[0].n_name = UDPSUM;
	nl[1].n_name = 0;

	if (nlist(KSYMS, nl)) {
		ns_debug(ns_log_default, 1, "ns_udp: nlist (%s,%s) failed",
			 KSYMS, UDPSUM);
		return;
	}

	ns_debug(ns_log_default, 1, "ns_udp: %s %d %lu (%ld)",
		 nl[0].n_name, nl[0].n_type, nl[0].n_value, nl[0].n_value);

	if (!nl[0].n_type)
		return;

	if ((fd = open(KMEM, O_RDWR, 0)) < 0) {
		ns_debug(ns_log_default, 1, "ns_udp: open %s failed: %s", KMEM,
			 strerror(errno));
		return;
	}

	offset = nl[0].n_value;
#ifdef KMAP
	offset &= ((~0UL)>>1);
#endif

	res = lseek(fd, offset, SEEK_SET);
	if (res != offset) {
		ns_debug(ns_log_default, 1, "ns_udp: lseek %lu failed %lu: %s",
			 offset, res, strerror(errno));
		goto cleanup;
	}

	if (read(fd, &sum, sizeof(sum)) != sizeof(sum)) {
		ns_debug(ns_log_default, 1, "ns_udp: read failed: %s",
			 strerror(errno));
		goto cleanup;
	}

	ns_debug(ns_log_default, 1, "ns_udp: %d", sum);
	if (sum == 0) {
#ifdef FIX_UDP_SUM
		sum = 1;
		lseek(fd, offset, SEEK_SET);
		if (res != offset) {
			ns_debug(ns_log_default, 1,
				 "ns_udp: lseek %lu failed %lu: %s",
				 offset, res, strerror(errno));
			goto cleanup;
		}
		if (write(fd, &sum, sizeof(sum)) != sizeof(sum)) {
			ns_debug(ns_log_default, 1, "ns_udp: write failed: %s",
				 strerror(errno));
			goto cleanup;
		}
		ns_warning(ns_log_default, "ns_udp: check sums turned on");
#else
		ns_panic(ns_log_default, 0,
			 "ns_udp: checksums NOT turned on, exiting");
#endif
	}
cleanup:
	close(fd);
#endif
}
OpenPOWER on IntegriCloud