Просмотр исходного кода

force-qtype-SOA: support clear qtype.

Nick Peng 1 год назад
Родитель
Сommit
950a0fba95
4 измененных файлов с 40 добавлено и 5 удалено
  1. 6 3
      etc/smartdns/smartdns.conf
  2. 2 0
      src/Makefile
  3. 25 1
      src/dns_conf.c
  4. 7 1
      src/util.c

+ 6 - 3
etc/smartdns/smartdns.conf

@@ -123,10 +123,13 @@ bind [::]:53
 # force-AAAA-SOA [yes|no]
 
 # force specific qtype return soa
-# force-qtype-SOA [qtypeid |...]
+# force-qtype-SOA [-,][qtypeid |...]
 # force-qtype-SOA [qtypeid|start_id-end_id|,...]
-# force-qtype-SOA 65 28
-# force-qtype-SOA 65,28
+# force-qtype-SOA 65 28 add type 65,28
+# force-qtype-SOA 65,28 add type 65,28
+# force-qtype-SOA 65-68 add type 65-68
+# force-qtype-SOA -,65-68, clear type 65-68
+# force-qtype-SOA - clear all type
 force-qtype-SOA 65
 
 # Enable IPV4, IPV6 dual stack IP optimization selection strategy

+ 2 - 0
src/Makefile

@@ -51,6 +51,8 @@ override CXXFLAGS +=-Iinclude
 # ldflags
 ifeq ($(STATIC), yes)
  override LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -lm -static
+else ifeq ($(SSL_STATIC), yes)
+ override LDFLAGS += -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lpthread -ldl -lm
 else
  override LDFLAGS += -lssl -lcrypto -lpthread -ldl -lm
 endif

+ 25 - 1
src/dns_conf.c

@@ -3554,11 +3554,27 @@ static int _conf_qtype_soa(uint8_t *soa_table, int argc, char *argv[])
 {
 	int i = 0;
 	int j = 0;
+	int is_clear = 0;
 
 	if (argc <= 1) {
 		return -1;
 	}
 
+	if (argc >= 2) {
+		if (strncmp(argv[1], "-", sizeof("-")) == 0) {
+			if (argc == 2) {
+				memset(soa_table, 0, MAX_QTYPE_NUM / 8 + 1);
+				return 0;
+			}
+
+			is_clear = 1;
+		}
+
+		if (strncmp(argv[1], "-,", sizeof(",")) == 0) {
+			is_clear = 1;
+		}
+	}
+
 	for (i = 1; i < argc; i++) {
 		char sub_arg[1024];
 		safe_strncpy(sub_arg, argv[i], sizeof(sub_arg));
@@ -3568,6 +3584,10 @@ static int _conf_qtype_soa(uint8_t *soa_table, int argc, char *argv[])
 				*dash = '\0';
 			}
 
+			if (*tok == '\0') {
+				continue;
+			}
+
 			long start = atol(tok);
 			long end = start;
 
@@ -3586,7 +3606,11 @@ static int _conf_qtype_soa(uint8_t *soa_table, int argc, char *argv[])
 			for (j = start; j <= end; j++) {
 				int offset = j / 8;
 				int bit = j % 8;
-				soa_table[offset] |= (1 << bit);
+				if (is_clear) {
+					soa_table[offset] &= ~(1 << bit);
+				} else {
+					soa_table[offset] |= (1 << bit);
+				}
 			}
 		}
 	}

+ 7 - 1
src/util.c

@@ -821,10 +821,16 @@ int netlink_get_neighbors(int family,
 	char buf[1024 * 16];
 	struct iovec iov = {buf, sizeof(buf)};
 	struct sockaddr_nl sa;
-	struct msghdr msg = {&sa, sizeof(sa), &iov, 1, NULL, 0, 0};
+	struct msghdr msg;
 	int len;
 	int ret = 0;
 
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_name = &sa;
+	msg.msg_namelen = sizeof(sa);
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+
 	nlh = (struct nlmsghdr *)buf;
 	nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
 	nlh->nlmsg_type = RTM_GETNEIGH;