Commit Diff
Diff:
b36746d80f9559a72037b8e5b6999f34507200fa
ce12744aeaf395f55d2780a7dd411d19fdd43492
Commit:
ce12744aeaf395f55d2780a7dd411d19fdd43492
Tree:
0e8fe62bbf42e406be8e95703ffab4f8373b6b3b
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sat Sep 25 11:58:59 2010 UTC
Message:
* make linux work for recursive namelookups tested on OpenSuse 10.3
blob - 016f88173e94ce213858a00f9653aad4ea7bf26c
blob + c2efd191c3d5d34bd342fe31efe8666bd29146c2
--- recurse.c
+++ recurse.c
@@ -67,7 +67,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.16 2010/09/25 11:08:07 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.17 2010/09/25 11:58:59 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -1565,7 +1565,11 @@ remove_zone(DB *db, struct domain *sd)
key.data = (char *)zone;
key.size = zonelen;
+#if DB_VERSION_MAJOR > 3
+ if (db->del(db, NULL, &key, 0) != 0) {
+#else
if (db->del(db, &key, 0) != 0) {
+#endif
syslog(LOG_ERR, "could not delete zone %s: %m", zone);
}
blob - bee8fa8e97aea852f3674f1d4fb56ef70adb37ec
blob + 72b3110853ec110e1ed763e89b9002bcf812800a
--- reply.c
+++ reply.c
@@ -56,7 +56,12 @@ void update_db(DB *, struct domain *);
struct domain * Lookup_zone(DB *db, char *name, u_int16_t namelen, u_int16_t type, int);
void collects_init(void);
+#ifdef __linux__
+static int udp_cksum(const struct iphdr *ip, const struct udphdr *up, int len);
+#else
static int udp_cksum(const struct ip *ip, const struct udphdr *up, int len);
+#endif
+
u_short in_cksum(const u_short *addr, register int len, int csum);
SLIST_HEAD(listhead, collects) collectshead;
@@ -70,7 +75,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.28 2010/09/25 11:08:07 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.29 2010/09/25 11:58:59 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -2094,15 +2099,42 @@ void
reply_raw2(int so, char *reply, int outlen, struct recurses *sr)
{
char buf[2048];
+#ifdef __linux__
+ struct iphdr *ip;
+#else
struct ip *ip;
+#endif
struct udphdr *udp;
int udplen = outlen + sizeof(struct udphdr);
struct sockaddr_in *sin_src, *sin_dst;
+#ifdef __linux__
+ ip = (struct iphdr *)&buf[0];
+#else
ip = (struct ip *)&buf[0];
+#endif
udp = (struct udphdr *)&buf[sizeof(struct ip)];
memcpy(&buf[sizeof(struct ip) + sizeof(struct udphdr)], reply, outlen);
+#ifdef __linux__
+ ip->version = IPVERSION;
+ ip->ihl = sizeof(struct iphdr) >> 2;
+
+ ip->tos = 0;
+ ip->tot_len = htons(udplen + sizeof(struct iphdr));
+ ip->id = arc4random() & 0xffff;
+ ip->frag_off = htons(IP_DF);
+ ip->ttl = 64;
+ ip->protocol = IPPROTO_UDP;
+ ip->check = 0;
+ sin_dst = (struct sockaddr_in *)(&sr->dest);
+ ip->saddr = sin_dst->sin_addr.s_addr;
+ sin_src = (struct sockaddr_in *)(&sr->source);
+ ip->daddr = sin_src->sin_addr.s_addr;
+
+ ip->check = 0;
+ ip->check = in_cksum((u_short*)ip, sizeof(struct iphdr), ip->check);
+#else
ip->ip_v = IPVERSION;
ip->ip_hl = sizeof(struct ip) >> 2;
@@ -2132,15 +2164,31 @@ reply_raw2(int so, char *reply, int outlen, struct rec
ip->ip_sum = 0;
ip->ip_sum = in_cksum((u_short*)ip, sizeof(struct ip), ip->ip_sum);
+#endif
+#ifdef __linux__
+
+ udp->source = sin_dst->sin_port;
+ udp->dest = sin_src->sin_port;
+ udp->len = htons(udplen);
+ udp->check = 0;
+
+ udp->check = udp_cksum(ip, udp, udplen);
+
+#else
udp->uh_sport = sin_dst->sin_port;
udp->uh_dport = sin_src->sin_port;
udp->uh_ulen = htons(udplen);
udp->uh_sum = 0;
udp->uh_sum = udp_cksum(ip, udp, udplen);
+#endif
+#ifdef __linux__
+ if (sendto(so, buf, sizeof(struct iphdr) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr)) < 0) {
+#else
if (sendto(so, buf, sizeof(struct ip) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr)) < 0) {
+#endif
syslog(LOG_ERR, "sendto: %m");
}
}
@@ -2170,7 +2218,11 @@ reply_raw2(int so, char *reply, int outlen, struct rec
*/
static int
+#ifdef __linux__
+udp_cksum(const struct iphdr *ip, const struct udphdr *up, int len)
+#else
udp_cksum(const struct ip *ip, const struct udphdr *up, int len)
+#endif
{
union phu {
struct phdr {
@@ -2189,8 +2241,13 @@ udp_cksum(const struct ip *ip, const struct udphdr *up
phu.ph.len = htons((u_int16_t)len);
phu.ph.mbz = 0;
phu.ph.proto = IPPROTO_UDP;
+#ifdef __linux__
+ memcpy(&phu.ph.src, &ip->saddr, sizeof(u_int32_t));
+ memcpy(&phu.ph.dst, &ip->daddr, sizeof(u_int32_t));
+#else
memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
+#endif
sp = &phu.pa[0];
sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
repomaster@centroid.eu