Commits

Markus Tzoe  committed 1621622

update protocol
- add protocol number;
- update report structure;
- update client.

  • Participants
  • Parent commits 4a4f4f6

Comments (0)

Files changed (4)

 void write_record(struct report* rt, struct sockaddr_in* src) {
 
     if (daemon->rprt_cond == 1) { // overwrite address to src addr in restrict mode.
-        my_syslog(LOG_INFO, _("restrict mode: overwrite record address from %X to %X"), rt->payload.record.addr.addr.addr4, src->sin_addr);
-        rt->payload.record.addr.addr.addr4 = src->sin_addr;
+        my_syslog(LOG_INFO, _("restrict mode: overwrite record address from %X to %X"), rt->payload.address.v4.sin_addr, src->sin_addr);
+        rt->payload.address.v4 = *src;
     }
 
     struct crec* cache = NULL;
     struct all_addr addr;
-    addr.addr = rt->payload.record.addr.addr;
-    char* canon = rt->payload.record.hostname;
+    addr.addr.addr4 = rt->payload.address.v4.sin_addr;
+    char* canon = rt->payload.hostname;
     unsigned short flag = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
     int in_host = 0;
     while((cache = cache_find_by_name(cache, canon, 0, F_IPV4))){

File src/dnsmasq.h

 /* reporter.c */
 #ifdef HAVE_RPRT
 void accept_report(struct listener *listen, time_t now);
+#define RPRT_PRNO 0x7F64u // protocol number
 enum flag
 {
     RPRT_PULL = 0x01,
     RPRT_PUSH = 0x02,
     RPRT_IPV6 = 0x04,
-    RPRT_ACKN = 0x08
+    RPRT_ACKN = 0x08,
+    RPRT_OKAY = 0x10,
+    RPRT_ABRT = 0x20
 };
 struct report
 {
-    unsigned int flags;
-    union
+    uint32_t proto;
+    unsigned short flags;
+    struct
     {
-        struct record
+        char hostname[32];
+        union
         {
-            char hostname[32];
-            struct all_addr addr;
-        } record;
+            struct sockaddr v0;
+            struct sockaddr_in v4;
+            struct sockaddr_in6 v6;
+        } address;
         uint64_t size;
     } payload;
 };

File src/nsreporter.c

     exit(1);
 }
 
+int checkhdr(struct report* rt) {
+    errno = 0;
+    if(rt->flags & RPRT_ABRT) {
+        errno = EPROTOTYPE;
+        return -1;
+    }
+    return 0;
+}
+
 int main(int argc, char const *argv[])
 {
     register char *cp;
 
     struct report report;
     memset(&report, 0, sizeof(struct report));
+    report.proto = RPRT_PRNO;
     report.flags = flag;
     char buffer[ADDRSTRLEN];
 
             }
             hname = hostname;
         }
-        memcpy(report.payload.record.hostname, hname, strlen(hname));
+        memcpy(report.payload.hostname, hname, strlen(hname));
         fprintf(stderr, "hostname: %s\n", hname);
 
         struct ifaddrs *ifaddr = NULL;
                         mark = ((struct sockaddr_in6 *)iap->ifa_addr)->sin6_addr._v6_ad_.__u6_addr16[0] & 0xFFFF;
                         if(mark != 0x0000 && mark != 0x80fe){
                             mark = 1;
-                            report.payload.record.addr.addr.addr6 = ((struct sockaddr_in6 *)iap->ifa_addr)->sin6_addr;
+                            report.payload.address.v6 = *((struct sockaddr_in6 *)iap->ifa_addr);
                         }
                         else mark = 0;
                         break;
                         mark = ((struct sockaddr_in *)iap->ifa_addr)->sin_addr.s_addr & 0xFF;
                         if(mark != 0x7F && mark != 0xc0){
                             mark = 1;
-                            report.payload.record.addr.addr.addr4 = ((struct sockaddr_in *)iap->ifa_addr)->sin_addr;
+                            report.payload.address.v4 = *((struct sockaddr_in *)iap->ifa_addr);
                         }
                         else mark = 0;
                         break;
                         perror("recv");
                         exit(1);
                     }
+                    if (checkhdr(&report) == -1) {
+                        perror("checkhdr");
+                        exit(1);
+                    }
 
                     if(report.flags & RPRT_IPV6)
                     {
-                        inet_ntop(AF_INET6, &(report.payload.record.addr.addr.addr6), buffer, ADDRSTRLEN);
+                        inet_ntop(AF_INET6, &(report.payload.address.v6.sin6_addr), buffer, ADDRSTRLEN);
                     }
                     else 
                     {
-                        inet_ntop(AF_INET, &(report.payload.record.addr.addr.addr4), buffer, ADDRSTRLEN);
+                        inet_ntop(AF_INET, &(report.payload.address.v4.sin_addr), buffer, ADDRSTRLEN);
                     }
-                    fprintf(stderr, "ok.\ndnsmasq server update cache [%s %s].\n", report.payload.record.hostname, buffer);
+                    fprintf(stderr, "ok.\ndnsmasq server update cache [%s %s].\n", report.payload.hostname, buffer);
                 }
             }
             close(sockfd);

File src/reporter.c

             my_syslog(LOG_ERR, ("%d: inet_ntop() error. abort cache insertion."), now);
             return;
         }
+
+        if(report.proto != RPRT_PRNO){
+            report.flags |= RPRT_ABRT;
+        }
+        else {
         
-        /*if (report.flags & RPRT_PULL)
-        {
-            //my_syslog(LOG_INFO, _("flag: PULL"));
-        }*/
+            /*if (report.flags & RPRT_PULL)
+            {
+                //my_syslog(LOG_INFO, _("flag: PULL"));
+            }*/
 
-        if (RPRT_PUSH & report.flags)
-        {
-            write_record(&report, &faddr);
+            if (RPRT_PUSH & report.flags)
+            {
+                write_record(&report, &faddr);
+            }
         }
+        
         if (RPRT_ACKN & report.flags)
         {
             reply_ack(fd, &report);