PERFORCE change 120769 for review
Fredrik Lindberg
fli at FreeBSD.org
Sat Jun 2 12:05:55 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=120769
Change 120769 by fli at fli_genesis on 2007/06/02 12:04:53
- Add and use MDNS_PKG_MAX_LEN instead of 9000
- Cap max number of bytes received via TCP to MDNS_PKG_MAX_LEN
- Use IPv6 header size instead of IPv4 when calculating packet size.
- Remove debugging macros that live in debug.h now.
Affected files ...
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.c#4 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.h#3 edit
Differences ...
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.c#4 (text+ko) ====
@@ -24,27 +24,30 @@
*
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <strings.h>
-#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/ioctl.h>
+#include <sys/uio.h>
+
#include <net/if.h>
+#include <net/if_dl.h>
+
#include <netinet/in.h>
#include <arpa/inet.h>
+
+#include <errno.h>
+#include <fcntl.h>
#include <ifaddrs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/sockio.h>
-#include <sys/uio.h>
-#include <net/if_dl.h>
-#include <err.h>
-#include <fcntl.h>
#include "mdns.h"
#include "stack_mdns.h"
+#include "debug.h"
static int mdns_udp_open(struct mdns *, int);
static int mdns_udp_close(struct mdns *, int);
@@ -105,16 +108,15 @@
error = ioctl(sock, SIOCGIFMTU, &req);
close(sock);
/*
- * IP-header (no options) and UDP-header
- * XXX: Will there ever be ip-options present in multicast packets?
+ * IPv6-header and UDP-header
*/
-#define _HDR_OVERHEAD (20 + 8)
+#define _HDR_OVERHEAD (40 + 8)
if (error != 0)
- md->md_maxpkgsz = 512;
+ md->md_maxpkgsz = MDNS_PKG_UDP_LEN;
else {
md->md_maxpkgsz = req.ifr_mtu - _HDR_OVERHEAD;
- if (md->md_maxpkgsz > 9000)
- md->md_maxpkgsz = 9000;
+ if (md->md_maxpkgsz > MDNS_PKG_MAX_LEN)
+ md->md_maxpkgsz = MDNS_PKG_MAX_LEN;
}
#undef _HDR_OVERHEAD
@@ -872,8 +874,9 @@
pkg->p_len += n;
MDNS_BUFLEN(buf) = n;
}
- if ((unsigned int)n < MDNS_BUFSZ(buf))
+ if ((unsigned int)n < MDNS_BUFSZ(buf) || pkg->p_len >= MDNS_PKG_MAX_LEN)
break;
+
buf = mdns_buf_alloc(md->md_bp, &pkg->p_buflist, 0, 0);
if (buf == NULL)
return (-1);
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.h#3 (text+ko) ====
@@ -28,22 +28,8 @@
#define _STACK_MDNS_H_
#include <wchar.h>
-#include <assert.h>
-
#include "stack_buf.h"
-/* Structure initialization protection */
-#define MDNS_MAGIC_COOKIE 0xcafebabe
-#ifdef DEBUG
-#define MDNS_INIT_SET(_md, f) (_md)->f = MDNS_MAGIC_COOKIE;
-#define MDNS_INIT_UNSET(_md, f) (_md)->f = ~MDNS_MAGIC_COOKIE;
-#define MDNS_INIT_ASSERT(_md, f) assert((_md)->f == MDNS_MAGIC_COOKIE);
-#else
-#define MDNS_INIT_SET(_md, f)
-#define MDNS_INIT_UNSET(_md, f)
-#define MDNS_INIT_ASSERT(_md, f)
-#endif
-
/* Multicast DNS constants */
#define MDNS_MCAST_INET "224.0.0.251" /* IPv4 multicast address */
#define MDNS_MCAST_INET6 "ff02::fb" /* IPv6 multicast address */
@@ -52,6 +38,7 @@
/* Header constants */
#define MDNS_PKG_LABEL_LEN 63
#define MDNS_PKG_UDP_LEN 512 /* legacy udp length */
+#define MDNS_PKG_MAX_LEN 9000 /* Maximum packet length */
#define MDNS_HEADER_LEN 12
#define MDNS_QSET_HLEN 4 /* qset header length */
#define MDNS_RRSET_HLEN 10 /* rrset header length */
More information about the p4-projects
mailing list