Skip to content

Commit bb78f49

Browse files
author
voxel
committed
Prepare to Version 1.0.2.43SF and tntegrate stock changes
1 parent 577a4d4 commit bb78f49

File tree

13,059 files changed

+5596982
-799106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

13,059 files changed

+5596982
-799106
lines changed

asm-openssl-1.0.2m.tar

-70 KB
Binary file not shown.

asm-openssl-1.0.2n.tar

70 KB
Binary file not shown.

git_home/datalib.git/datalib

36 Bytes
Binary file not shown.

git_home/datalib.git/libconfig.so

-104 Bytes
Binary file not shown.

git_home/dni-nat2.5.git/clbr.ko

-4 Bytes
Binary file not shown.

git_home/dnsmasq.git/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CFLAGS?= -O2
1212
all : dnsmasq
1313

1414
dnsmasq :
15-
$(MAKE) I18N=-DNO_GETTEXT -f ../bld/Makefile -C $(SRC) dnsmasq
15+
$(MAKE) I18N=-DNO_GETTEXT -f ../bld/Makefile -C $(SRC) dnsmasq -lconfig
1616

1717
clean :
1818
rm -f *~ $(SRC)/*.mo contrib/*/*~ */*~ $(SRC)/*.pot

git_home/dnsmasq.git/src/dnsmasq.c

+27-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ static char *compile_opts =
4747
static pid_t pid;
4848
static int pipewrite;
4949

50+
/* libconfig.so */
51+
extern char *config_get(char *name);
52+
extern int config_match(char *name, char *match);
53+
5054
#ifdef DNI_IPV6_FEATURE
5155
extern void check_timeout_forward(struct daemon *daemon, time_t now);
5256
#endif
@@ -853,7 +857,7 @@ static int set_dns_listeners(struct daemon *daemon, time_t now, fd_set *set, int
853857
/* death of a child goes through the select loop, so
854858
we don't need to explicitly arrange to wake up here */
855859
for (i = 0; i < MAX_PROCS; i++)
856-
if (daemon->tcp_pids[i] == 0)
860+
if ( daemon->tcp_pids[i] == 0 && listener->tcpfd != -1 )
857861
{
858862
FD_SET(listener->tcpfd, set);
859863
bump_maxfd(listener->tcpfd, maxfdp);
@@ -877,6 +881,8 @@ static void check_dns_listeners(struct daemon *daemon, fd_set *set, time_t now)
877881
{
878882
struct serverfd *serverfdp;
879883
struct listener *listener;
884+
char *buf = NULL;
885+
short dial_flag = 0;
880886

881887
for (serverfdp = daemon->sfds; serverfdp; serverfdp = serverfdp->next)
882888
if (FD_ISSET(serverfdp->fd, set))
@@ -885,14 +891,32 @@ static void check_dns_listeners(struct daemon *daemon, fd_set *set, time_t now)
885891
for (listener = daemon->listeners; listener; listener = listener->next)
886892
{
887893
if (FD_ISSET(listener->fd, set))
888-
receive_query(listener, daemon, now);
894+
{
895+
buf = config_get("wan_proto");
896+
if(!strncmp(buf, "pppoe", 5) || !strncmp(buf, "pptp", 4) || !strncmp(buf, "l2tp", 4))
897+
{
898+
if(config_match("wan_pppoe_demand","1")
899+
|| config_match("wan_pptp_demand","1")
900+
|| config_match("wan_l2tp_demand","1"))
901+
{
902+
dial_flag = 1;
903+
system("echo \"1\">/proc/sys/net/dni/dial_on_demand_dns");
904+
}
905+
}
906+
if(listener->family == AF_PACKET)
907+
receive_raw_query(listener, daemon, now);
908+
else
909+
receive_query(listener, daemon, now);
910+
if(dial_flag)
911+
system("echo \"0\">/proc/sys/net/dni/dial_on_demand_dns");
912+
}
889913

890914
#ifdef HAVE_TFTP
891915
if (listener->tftpfd != -1 && FD_ISSET(listener->tftpfd, set))
892916
tftp_request(listener, daemon, now);
893917
#endif
894918

895-
if (FD_ISSET(listener->tcpfd, set))
919+
if (listener->tcpfd != -1 && FD_ISSET(listener->tcpfd, set))
896920
{
897921
int confd;
898922
struct irec *iface = NULL;

git_home/dnsmasq.git/src/dnsmasq.h

+43-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
#include <sys/types.h>
1717
#include <netinet/in.h>
1818

19+
extern char *config_get(char *name);
20+
1921
/*
2022
* Advanced API
2123
* source interface/address selection, source routing, etc...
2224
* *under construction*
2325
* (this struct is copy from linux/ipv6.h). since netinet/in.h doesn't
2426
* have this struct.
2527
*/
28+
2629
struct in6_pktinfo {
2730
struct in6_addr ipi6_addr;
2831
int ipi6_ifindex;
@@ -99,6 +102,15 @@ extern int capset(cap_user_header_t header, cap_user_data_t data);
99102
#include <sys/prctl.h>
100103
#endif
101104

105+
#ifdef HAVE_IPV6
106+
#include <linux/if_packet.h>
107+
#include <linux/if_ether.h>
108+
#include <asm/byteorder.h>
109+
#include <linux/filter.h>
110+
#include <linux/udp.h>
111+
#include <linux/icmpv6.h>
112+
#endif
113+
102114
/* Min buffer size: we check after adding each record, so there must be
103115
memory for the largest packet, and the largest record so the
104116
min for DNS is PACKETSZ+MAXDNAME+RRFIXEDSZ which is < 1000.
@@ -141,7 +153,7 @@ extern int capset(cap_user_header_t header, cap_user_data_t data);
141153
#ifdef SUP_STATIC_PPTP
142154
#define DEF_STATIC_PPTP_CONFIG "/tmp/pptp.conf"
143155
#endif
144-
156+
#pragma pack(1)
145157
struct all_addr {
146158
union {
147159
struct in_addr addr4;
@@ -489,6 +501,33 @@ typedef unsigned char u8;
489501
typedef unsigned short u16;
490502
typedef unsigned int u32;
491503

504+
#ifdef HAVE_IPV6
505+
struct ipv6hdr {
506+
#if defined(__LITTLE_ENDIAN_BITFIELD)
507+
u8 priority:4,
508+
version:4;
509+
#elif defined(__BIG_ENDIAN_BITFIELD)
510+
u8 version:4,
511+
priority:4;
512+
#endif
513+
u8 flow_lbl[3];
514+
u16 payload_len;
515+
u8 nexthdr;
516+
u8 hop_limit;
517+
struct in6_addr saddr;
518+
struct in6_addr daddr;
519+
};
520+
521+
struct udp_dns_packet {
522+
struct ethhdr eth;
523+
struct ipv6hdr ip6;
524+
struct udphdr udp;
525+
char data[256];
526+
};
527+
528+
#define IP6VERSION 6
529+
#define DNS_PORT 53
530+
#endif
492531

493532
struct dhcp_packet {
494533
u8 op, htype, hlen, hops;
@@ -688,6 +727,8 @@ int check_for_local_domain(char *name, time_t now, struct daemon *daemon);
688727
unsigned int questions_crc(HEADER *header, size_t plen, char *buff);
689728
size_t resize_packet(HEADER *header, size_t plen,
690729
unsigned char *pheader, size_t hlen);
730+
extern int get_lan_linklocal_ipaddr6(struct in6_addr *inp6, int global_flag);
731+
extern int get_lan_ipaddr(struct in_addr *inp);
691732
#ifdef SUP_STATIC_PPTP
692733
extern unsigned char *ex_skip_questions(HEADER *header, size_t plen);
693734
#endif
@@ -853,4 +894,5 @@ extern unsigned char *get_resolve_address(int *addrcount, struct in_addr *ip_add
853894
extern struct dname_record *dname_list;
854895
extern char *dname_check_file;
855896
extern time_t dname_save_time;
897+
#pragma pack()
856898
//endif

git_home/dnsmasq.git/src/forward.c

+206
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,212 @@ void reply_query(struct serverfd *sfd, struct daemon *daemon, time_t now)
858858
}
859859
}
860860

861+
#pragma pack(1)
862+
static unsigned short checksum(unsigned short *start, int len)
863+
{
864+
unsigned int sum = 0;
865+
unsigned short *w = start;
866+
unsigned short answer = 0;
867+
while (1 < len) {
868+
sum += *w++;
869+
len -= 2;
870+
}
871+
if (1 == len) {
872+
*(unsigned char *)(&answer) = *(unsigned char *)w;
873+
sum += answer;
874+
}
875+
while (sum >> 16)
876+
sum = (sum & 0xffff) + (sum >> 16);
877+
return (unsigned short)~sum;
878+
}
879+
880+
void receive_raw_query(struct listener *listen, struct daemon *daemon, time_t now)
881+
{
882+
if(config_match("ap_mode", "0"))
883+
return 0;
884+
885+
HEADER *reply_header ;
886+
unsigned int fromlen = 0;
887+
struct sockaddr_in6 src;
888+
struct udp_dns_packet rawhdr;
889+
struct udp_dns_packet *packet, *pkt;
890+
char buf[1024] = {0}, none_addr[16] = {0}, buf1[1024]={0};
891+
char linkprefix[] = {0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
892+
int bytes, n, i, flag = 0;
893+
u_int16_t check;
894+
struct in6_addr source, dest;
895+
char *data, *p, dns[256];
896+
char sendbuf[1500];
897+
898+
fromlen = sizeof(src);
899+
memset(&src, 0x00, sizeof(src));
900+
memset(&rawhdr, 0x00, sizeof(struct udp_dns_packet));
901+
memset(buf, 0x00, sizeof(buf));
902+
903+
bytes = recvfrom(listen->fd, buf, 1024, 0, (struct sockaddr *)&src, &fromlen);
904+
905+
if(bytes < 0)
906+
{
907+
my_syslog(LOG_INFO, "couldn't read on raw listening socket -- ignoring");
908+
return;
909+
}
910+
911+
/* for (i=0; i<112; i++) {
912+
fprintf(stderr, "%02x ", buf[i]);
913+
if (i % 16 == 15) fprintf(stderr, "\n");
914+
}
915+
*/
916+
my_syslog(LOG_INFO, "recv message bytes %d", bytes);
917+
918+
memcpy(&rawhdr, buf, sizeof(struct udp_dns_packet));
919+
packet = (struct udp_dns_packet *)buf;
920+
memset(buf1, 0x00, sizeof(buf1));
921+
pkt = (struct udp_dns_packet *)buf1;
922+
923+
if(bytes < (int) (sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct udphdr)))
924+
{
925+
my_syslog(LOG_INFO, "message too short, ignoring");
926+
return;
927+
}
928+
929+
if(rawhdr.ip6.nexthdr != IPPROTO_UDP || rawhdr.udp.dest != htons(DNS_PORT) || rawhdr.ip6.payload_len != rawhdr.udp.len )
930+
{
931+
my_syslog(LOG_INFO, "unrelated/bogus packet nexthdr %x proto %x port %x payload %x", ntohs(rawhdr.ip6.nexthdr), ntohs(rawhdr.eth.h_proto), ntohs(rawhdr.udp.dest), ntohs(rawhdr.ip6.payload_len));
932+
return;
933+
}
934+
935+
if(!memcmp(&(rawhdr.ip6.saddr), none_addr, 2))
936+
{
937+
my_syslog(LOG_INFO, "ignore src :");
938+
return;
939+
}
940+
941+
/*psuedo-header*/
942+
source = rawhdr.ip6.saddr;
943+
dest = rawhdr.ip6.daddr;
944+
check = rawhdr.udp.check;
945+
rawhdr.udp.check = 0;
946+
memset(&rawhdr.ip6, 0, sizeof(rawhdr.ip6));
947+
packet->udp.check = 0;
948+
memset(&(packet->ip6), 0, sizeof(rawhdr.ip6));
949+
950+
rawhdr.ip6.hop_limit = IPPROTO_UDP; /*psuedo-header the protocol must add on hop limit to create correct checksum*/
951+
rawhdr.ip6.saddr = source;
952+
rawhdr.ip6.daddr = dest;
953+
rawhdr.ip6.payload_len = rawhdr.udp.len;
954+
955+
packet->ip6.hop_limit = IPPROTO_UDP;
956+
packet->ip6.saddr = source;
957+
packet->ip6.daddr = dest;
958+
packet->ip6.payload_len = rawhdr.udp.len;
959+
960+
if (check && check != checksum(&packet->ip6, bytes)) {
961+
my_syslog(LOG_INFO, "packet with bad UDP checksum received, %02x ignorin ", ntohs(check));
962+
return -2;
963+
}
964+
965+
memcpy(sendbuf, rawhdr.data, (sizeof(rawhdr.data)));
966+
data = rawhdr.data;
967+
p = &dns[0];
968+
/* add the response */
969+
int tolen = 0, msglen;
970+
struct sockaddr_in6 dst;
971+
unsigned char dns_ver;
972+
struct in6_addr source_addr, global_addr;
973+
struct in_addr local_addr4;
974+
char *ansp = (unsigned char *)(sendbuf + ntohs(rawhdr.udp.len) -8);
975+
976+
if (*(ansp-3) == 0x1c )
977+
dns_ver = 6;
978+
else
979+
dns_ver = 4;
980+
PUTSHORT(0x0c | 0xc000, ansp);
981+
982+
if (dns_ver == 6 ) //ipv6 dns
983+
{
984+
PUTSHORT(T_AAAA, ansp);
985+
} else {
986+
PUTSHORT(T_A, ansp);
987+
if(!get_lan_ipaddr(&local_addr4))
988+
{
989+
return -1;
990+
}
991+
}
992+
993+
if(get_lan_linklocal_ipaddr6(&source_addr, 0) < 0)
994+
return -1;
995+
996+
PUTSHORT(C_IN, ansp);
997+
PUTLONG(0, ansp);
998+
if(dns_ver == 6)
999+
PUTSHORT(16, ansp);
1000+
else
1001+
PUTSHORT(INADDRSZ, ansp);
1002+
if(dns_ver == 6)
1003+
{
1004+
if(get_lan_linklocal_ipaddr6(&global_addr, 1) < 0)
1005+
if(get_lan_linklocal_ipaddr6(&global_addr, 0) < 0)
1006+
return -1;
1007+
1008+
memcpy(ansp, &global_addr, 16);
1009+
ansp +=16;
1010+
}
1011+
else
1012+
{
1013+
memcpy(ansp, &local_addr4, 4);
1014+
ansp +=4;
1015+
}
1016+
reply_header = (HEADER *)(sendbuf);
1017+
reply_header->qr = 1;
1018+
reply_header->aa = 1;
1019+
reply_header->ra = 1;
1020+
reply_header->tc = 0;
1021+
reply_header->rcode = NOERROR;
1022+
reply_header->ancount = htons(1);
1023+
reply_header->nscount = htons(0);
1024+
reply_header->arcount = htons(0);
1025+
1026+
msglen = ansp - sendbuf;
1027+
1028+
tolen =sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct udphdr) + msglen;
1029+
1030+
/* pack packet */
1031+
pkt->ip6.hop_limit = IPPROTO_UDP;
1032+
pkt->ip6.saddr = dest;
1033+
pkt->ip6.daddr = source;
1034+
pkt->udp.check = 0;
1035+
1036+
pkt->udp.dest = packet->udp.source;
1037+
pkt->udp.source = packet->udp.dest;
1038+
pkt->udp.len = htons (sizeof(struct udphdr) + msglen);
1039+
pkt->ip6.payload_len = pkt->udp.len;
1040+
memcpy(pkt->data, sendbuf, msglen);
1041+
1042+
pkt->udp.check = checksum((unsigned short *)&pkt->ip6, tolen);
1043+
my_syslog(LOG_INFO, " pkt %02x", pkt->udp.check);
1044+
1045+
pkt->ip6.priority = 0;
1046+
pkt->ip6.version = 6;
1047+
pkt->ip6.flow_lbl[0] = 0;
1048+
pkt->ip6.flow_lbl[1] = 0;
1049+
pkt->ip6.flow_lbl[2] = 0;
1050+
pkt->ip6.nexthdr = IPPROTO_UDP;
1051+
pkt->ip6.hop_limit = IPDEFTTL;
1052+
1053+
memcpy(pkt->eth.h_dest, rawhdr.eth.h_source, ETH_ALEN);
1054+
memcpy(pkt->eth.h_source, rawhdr.eth.h_dest, ETH_ALEN);
1055+
pkt->eth.h_proto = htons(ETH_P_IPV6);
1056+
1057+
memset(&dst, 0x00, sizeof(dst));
1058+
dst.sin6_family = htons(AF_INET6);
1059+
dst.sin6_addr = rawhdr.ip6.saddr;
1060+
my_syslog(LOG_INFO, "send dns packet, sockfd = %d", listen->fd);
1061+
if (0 >= send(listen->fd, pkt, tolen, 0)) {
1062+
my_syslog(LOG_INFO,"sendto failure! %s\n", strerror(errno));
1063+
}
1064+
1065+
}
1066+
#pragma pack()
8611067
void receive_query(struct listener *listen, struct daemon *daemon, time_t now)
8621068
{
8631069
HEADER *header = (HEADER *)daemon->packet;

0 commit comments

Comments
 (0)