Skip to contentSkip to conversation

slirp: kill ugly macros

PATCH In review Michael S. Tsirkin 4 participants 7 messages Feb 15, 2012 – Feb 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp: kill ugly macros

Remove ugly macros for field names,
change done by the following script:

s#\bifq_prev\b#m_prev#g;
s#\bifq_next\b#m_next#g;
s#\bifs_prev\b#m_prevpkt#g;
s#\bifs_next\b#m_nextpkt#g;
s#\bifq_so\b#m_so#g;
s#\bm_next\b#m_hdr.mh_next#g;
s#\bm_prev\b#m_hdr.mh_prev#g;
s#\bm_nextpkt\b#m_hdr.mh_nextpkt#g;
s#\bm_prevpkt\b#m_hdr.mh_prevpkt#g;
s#\bm_flags\b#m_hdr.mh_flags#g;
s#\bm_len\b#m_hdr.mh_len#g;
s#\bm_data\b#m_hdr.mh_data#g;
s#\bm_size\b#m_hdr.mh_size#g;
s#\bm_dat\b#M_dat.m_dat_#g;
s#\bm_ext\b#M_dat.m_ext_#g;
s#\bm_so\b#m_hdr.mh_so#g;

---

Lightly tested, WFM

 slirp/bootp.c      |    8 ++--
 slirp/cksum.c      |    4 +-
 slirp/if.c         |   70 +++++++++++++++++++++---------------------
 slirp/if.h         |    2 +-
 slirp/ip.h         |    2 +-
 slirp/ip_icmp.c    |   64 +++++++++++++++++++-------------------
 slirp/ip_input.c   |   34 ++++++++++----------
 slirp/ip_output.c  |   14 ++++----
 slirp/mbuf.c       |   86 ++++++++++++++++++++++++++--------------------------
 slirp/mbuf.h       |   36 +++++----------------
 slirp/sbuf.c       |   20 ++++++------
 slirp/slirp.c      |   16 +++++-----
 slirp/socket.c     |   12 ++++----
 slirp/tcp_input.c  |   18 +++++-----
 slirp/tcp_output.c |   14 ++++----
 slirp/tcp_subr.c   |   62 +++++++++++++++++++-------------------
 slirp/tftp.c       |   38 +++++++++++-----------
 slirp/udp.c        |   26 ++++++++--------
 18 files changed, 254 insertions(+), 272 deletions(-)
slirp/bootp.c +4 -4
index efd1fe7..84c1182 100644
@@ -173,9 +173,9 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
     if (!m) {
         return;
     }
-    m->m_data += IF_MAXLINKHDR;
-    rbp = (struct bootp_t *)m->m_data;
-    m->m_data += sizeof(struct udpiphdr);
+    m->m_hdr.mh_data += IF_MAXLINKHDR;
+    rbp = (struct bootp_t *)m->m_hdr.mh_data;
+    m->m_hdr.mh_data += sizeof(struct udpiphdr);
     memset(rbp, 0, sizeof(struct bootp_t));
 
     if (dhcp_msg_type == DHCPDISCOVER) {
@@ -304,7 +304,7 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
 
     daddr.sin_addr.s_addr = 0xffffffffu;
 
-    m->m_len = sizeof(struct bootp_t) -
+    m->m_hdr.mh_len = sizeof(struct bootp_t) -
         sizeof(struct ip) - sizeof(struct udphdr);
     udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
 }
slirp/cksum.c +2 -2
index e43867d..123dead 100644
@@ -61,11 +61,11 @@ int cksum(struct mbuf *m, int len)
 		uint32_t l;
 	} l_util;
 
-	if (m->m_len == 0)
+	if (m->m_hdr.mh_len == 0)
 	   goto cont;
 	w = mtod(m, uint16_t *);
 
-	mlen = m->m_len;
+	mlen = m->m_hdr.mh_len;
 
 	if (len < mlen)
 	   mlen = len;
slirp/if.c +35 -35

154 lines not on this page · raw message

slirp/if.h +1 -1
index 2dac1c7..e0d426e 100644
@@ -20,6 +20,6 @@
 /* 2 for alignment, 14 for ethernet, 40 for TCP/IP */
 #define IF_MAXLINKHDR (2 + 14 + 40)
 
-#define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm))
+#define ifs_init(ifm) ((ifm)->m_hdr.mh_nextpkt = (ifm)->m_hdr.mh_prevpkt = (ifm))
 
 #endif
slirp/ip.h +1 -1
index 88c903f..5dc1a8a 100644
@@ -241,7 +241,7 @@ struct	ipasfrag {
  * Structure stored in mbuf in inpcb.ip_options
  * and passed to ip_output when ip options are in use.
  * The actual length of the options (including ipopt_dst)
- * is in m_len.
+ * is in m_hdr.mh_len.
  */
 #define MAX_IPOPTLEN	40
 
slirp/ip_icmp.c +32 -32

164 lines not on this page · raw message

slirp/ip_input.c +17 -17
index c7b3eb4..046e468 100644
@@ -74,9 +74,9 @@ ip_input(struct mbuf *m)
 
 	DEBUG_CALL("ip_input");
 	DEBUG_ARG("m = %lx", (long)m);
-	DEBUG_ARG("m_len = %d", m->m_len);
+	DEBUG_ARG("m_hdr.mh_len = %d", m->m_hdr.mh_len);
 
-	if (m->m_len < sizeof (struct ip)) {
+	if (m->m_hdr.mh_len < sizeof (struct ip)) {
 		return;
 	}
 
@@ -87,7 +87,7 @@ ip_input(struct mbuf *m)
 	}
 
 	hlen = ip->ip_hl << 2;
-	if (hlen<sizeof(struct ip ) || hlen>m->m_len) {/* min header length */
+	if (hlen<sizeof(struct ip ) || hlen>m->m_hdr.mh_len) {/* min header length */
 	  goto bad;                                  /* or packet too short */
 	}
 
@@ -115,13 +115,13 @@ ip_input(struct mbuf *m)
 	 * Trim mbufs if longer than we expect.
 	 * Drop packet if shorter than we expect.
 	 */
-	if (m->m_len < ip->ip_len) {
+	if (m->m_hdr.mh_len < ip->ip_len) {
 		goto bad;
 	}
 
 	/* Should drop packet if mbuf too long? hmmm... */
-	if (m->m_len > ip->ip_len)
-	   m_adj(m, ip->ip_len - m->m_len);
+	if (m->m_hdr.mh_len > ip->ip_len)
+	   m_adj(m, ip->ip_len - m->m_hdr.mh_len);
 
 	/* check ip_ttl for a correct ICMP reply */
 	if(ip->ip_ttl==0) {
@@ -233,10 +233,10 @@ ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
 	/*
 	 * Presence of header sizes in mbufs
 	 * would confuse code below.
-         * Fragment m_data is concatenated.
+         * Fragment m_hdr.mh_data is concatenated.
 	 */
-	m->m_data += hlen;
-	m->m_len -= hlen;
+	m->m_hdr.mh_data += hlen;
+	m->m_hdr.mh_len -= hlen;
 
 	/*
 	 * If first fragment to arrive, create a reassembly queue.
@@ -342,13 +342,13 @@ insert:
 	/*
 	 * If the fragments concatenated to an mbuf that's
 	 * bigger than the total size of the fragment, then and
-	 * m_ext buffer was alloced. But fp->ipq_next points to
+	 * M_dat.m_ext_ buffer was alloced. But fp->ipq_next points to
 	 * the old buffer (in the mbuf), so we must point ip
 	 * into the new buffer.
 	 */
-	if (m->m_flags & M_EXT) {
-	  int delta = (char *)q - m->m_dat;
-	  q = (struct ipasfrag *)(m->m_ext + delta);
+	if (m->m_hdr.mh_flags & M_EXT) {
+	  int delta = (char *)q - m->M_dat.m_dat_;
+	  q = (struct ipasfrag *)(m->M_dat.m_ext_ + delta);
 	}
 
     ip = fragtoip(q);
@@ -358,8 +358,8 @@ insert:
 	ip->ip_dst = fp->ipq_dst;
 	remque(&fp->ip_link);
 	(void) m_free(dtom(slirp, fp));
-	m->m_len += (ip->ip_hl << 2);
-	m->m_data -= (ip->ip_hl << 2);
+	m->m_hdr.mh_len += (ip->ip_hl << 2);
+	m->m_hdr.mh_data -= (ip->ip_hl << 2);
 
 	return ip;
 
@@ -654,9 +654,9 @@ ip_stripoptions(register struct mbuf *m, struct mbuf *mopt)
 
 	olen = (ip->ip_hl<<2) - sizeof (struct ip);
 	opts = (caddr_t)(ip + 1);
-	i = m->m_len - (sizeof (struct ip) + olen);
+	i = m->m_hdr.mh_len - (sizeof (struct ip) + olen);
 	memcpy(opts, opts  + olen, (unsigned)i);
-	m->m_len -= olen;
+	m->m_hdr.mh_len -= olen;
 
 	ip->ip_hl = sizeof(struct ip) >> 2;
 }
slirp/ip_output.c +7 -7
index c82830f..5f41c7a 100644
@@ -102,7 +102,7 @@ ip_output(struct socket *so, struct mbuf *m0)
 
     {
 	int mhlen, firstlen = len;
-	struct mbuf **mnext = &m->m_nextpkt;
+	struct mbuf **mnext = &m->m_hdr.mh_nextpkt;
 
 	/*
 	 * Loop through length of segment after first fragment,
@@ -117,11 +117,11 @@ ip_output(struct socket *so, struct mbuf *m0)
 	    error = -1;
 	    goto sendorfree;
 	  }
-	  m->m_data += IF_MAXLINKHDR;
+	  m->m_hdr.mh_data += IF_MAXLINKHDR;
 	  mhip = mtod(m, struct ip *);
 	  *mhip = *ip;
 
-	  m->m_len = mhlen;
+	  m->m_hdr.mh_len = mhlen;
 	  mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
 	  if (ip->ip_off & IP_MF)
 	    mhip->ip_off |= IP_MF;
@@ -140,7 +140,7 @@ ip_output(struct socket *so, struct mbuf *m0)
 	  mhip->ip_sum = 0;
 	  mhip->ip_sum = cksum(m, mhlen);
 	  *mnext = m;
-	  mnext = &m->m_nextpkt;
+	  mnext = &m->m_hdr.mh_nextpkt;
 	}
 	/*
 	 * Update first fragment by trimming what's been copied out
@@ -148,14 +148,14 @@ ip_output(struct socket *so, struct mbuf *m0)
 	 */
 	m = m0;
 	m_adj(m, hlen + firstlen - (uint16_t)ip->ip_len);
-	ip->ip_len = htons((uint16_t)m->m_len);
+	ip->ip_len = htons((uint16_t)m->m_hdr.mh_len);
 	ip->ip_off = htons((uint16_t)(ip->ip_off | IP_MF));
 	ip->ip_sum = 0;
 	ip->ip_sum = cksum(m, hlen);
 sendorfree:
 	for (m = m0; m; m = m0) {
-		m0 = m->m_nextpkt;
-                m->m_nextpkt = NULL;
+		m0 = m->m_hdr.mh_nextpkt;
+                m->m_hdr.mh_nextpkt = NULL;
 		if (error == 0)
 			if_output(so, m);
 		else
slirp/mbuf.c +43 -43

180 lines not on this page · raw message

slirp/mbuf.h +9 -27
index 0708840..292cbb3 100644
@@ -39,14 +39,14 @@
  * Macros for type conversion
  * mtod(m,t) -	convert mbuf pointer to data pointer of correct type
  */
-#define mtod(m,t)	((t)(m)->m_data)
+#define mtod(m,t)	((t)(m)->m_hdr.mh_data)
 
 /* XXX About mbufs for slirp:
  * Only one mbuf is ever used in a chain, for each "cell" of data.
- * m_nextpkt points to the next packet, if fragmented.
+ * m_hdr.mh_nextpkt points to the next packet, if fragmented.
  * If the data is too large, the M_EXT is used, and a larger block
  * is alloced.  Therefore, m_free[m] must check for M_EXT and if set
- * free the m_ext.  This is inefficient memory-wise, but who cares.
+ * free the M_dat.m_ext_.  This is inefficient memory-wise, but who cares.
  */
 
 /* XXX should union some of these! */
@@ -66,17 +66,17 @@ struct m_hdr {
 };
 
 /*
- * How much room is in the mbuf, from m_data to the end of the mbuf
+ * How much room is in the mbuf, from m_hdr.mh_data to the end of the mbuf
  */
-#define M_ROOM(m) ((m->m_flags & M_EXT)? \
-			(((m)->m_ext + (m)->m_size) - (m)->m_data) \
+#define M_ROOM(m) ((m->m_hdr.mh_flags & M_EXT)? \
+			(((m)->M_dat.m_ext_ + (m)->m_hdr.mh_size) - (m)->m_hdr.mh_data) \
 		   : \
-			(((m)->m_dat + (m)->m_size) - (m)->m_data))
+			(((m)->M_dat.m_dat_ + (m)->m_hdr.mh_size) - (m)->m_hdr.mh_data))
 
 /*
  * How much free room there is
  */
-#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
+#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_hdr.mh_len)
 #define M_TRAILINGSPACE M_FREEROOM
 
 struct mbuf {
@@ -91,25 +91,7 @@ struct mbuf {
 	} M_dat;
 };
 
-#define m_next		m_hdr.mh_next
-#define m_prev		m_hdr.mh_prev
-#define m_nextpkt	m_hdr.mh_nextpkt
-#define m_prevpkt	m_hdr.mh_prevpkt
-#define m_flags		m_hdr.mh_flags
-#define	m_len		m_hdr.mh_len
-#define	m_data		m_hdr.mh_data
-#define m_size		m_hdr.mh_size
-#define m_dat		M_dat.m_dat_
-#define m_ext		M_dat.m_ext_
-#define m_so		m_hdr.mh_so
-
-#define ifq_prev m_prev
-#define ifq_next m_next
-#define ifs_prev m_prevpkt
-#define ifs_next m_nextpkt
-#define ifq_so m_so
-
-#define M_EXT			0x01	/* m_ext points to more (malloced) data */
+#define M_EXT			0x01	/* M_dat.m_ext_ points to more (malloced) data */
 #define M_FREELIST		0x02	/* mbuf is on free list */
 #define M_USEDLIST		0x04	/* XXX mbuf is on used list (for dtom()) */
 #define M_DOFREE		0x08	/* when m_free is called on the mbuf, free()
slirp/sbuf.c +10 -10
index 5a1ccbf..182e643 100644
@@ -68,10 +68,10 @@ sbappend(struct socket *so, struct mbuf *m)
 	DEBUG_CALL("sbappend");
 	DEBUG_ARG("so = %lx", (long)so);
 	DEBUG_ARG("m = %lx", (long)m);
-	DEBUG_ARG("m->m_len = %d", m->m_len);
+	DEBUG_ARG("m->m_hdr.mh_len = %d", m->m_hdr.mh_len);
 
 	/* Shouldn't happen, but...  e.g. foreign host closes connection */
-	if (m->m_len <= 0) {
+	if (m->m_hdr.mh_len <= 0) {
 		m_free(m);
 		return;
 	}
@@ -93,7 +93,7 @@ sbappend(struct socket *so, struct mbuf *m)
 	 * ottherwise it'll arrive out of order, and hence corrupt
 	 */
 	if (!so->so_rcv.sb_cc)
-	   ret = slirp_send(so, m->m_data, m->m_len, 0);
+	   ret = slirp_send(so, m->m_hdr.mh_data, m->m_hdr.mh_len, 0);
 
 	if (ret <= 0) {
 		/*
@@ -103,13 +103,13 @@ sbappend(struct socket *so, struct mbuf *m)
 		 * it will be detected in the normal way by soread()
 		 */
 		sbappendsb(&so->so_rcv, m);
-	} else if (ret != m->m_len) {
+	} else if (ret != m->m_hdr.mh_len) {
 		/*
 		 * Something was written, but not everything..
 		 * sbappendsb the rest
 		 */
-		m->m_len -= ret;
-		m->m_data += ret;
+		m->m_hdr.mh_len -= ret;
+		m->m_hdr.mh_data += ret;
 		sbappendsb(&so->so_rcv, m);
 	} /* else */
 	/* Whatever happened, we free the mbuf */
@@ -125,23 +125,23 @@ sbappendsb(struct sbuf *sb, struct mbuf *m)
 {
 	int len, n,  nn;
 
-	len = m->m_len;
+	len = m->m_hdr.mh_len;
 
 	if (sb->sb_wptr < sb->sb_rptr) {
 		n = sb->sb_rptr - sb->sb_wptr;
 		if (n > len) n = len;
-		memcpy(sb->sb_wptr, m->m_data, n);
+		memcpy(sb->sb_wptr, m->m_hdr.mh_data, n);
 	} else {
 		/* Do the right edge first */
 		n = sb->sb_data + sb->sb_datalen - sb->sb_wptr;
 		if (n > len) n = len;
-		memcpy(sb->sb_wptr, m->m_data, n);
+		memcpy(sb->sb_wptr, m->m_hdr.mh_data, n);
 		len -= n;
 		if (len) {
 			/* Now the left edge */
 			nn = sb->sb_rptr - sb->sb_data;
 			if (nn > len) nn = len;
-			memcpy(sb->sb_data,m->m_data+n,nn);
+			memcpy(sb->sb_data,m->m_hdr.mh_data+n,nn);
 			n += nn;
 		}
 	}
slirp/slirp.c +8 -8
index 19d69eb..b33211c 100644
@@ -679,11 +679,11 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
         if (M_FREEROOM(m) < pkt_len + 2) {
             m_inc(m, pkt_len + 2);
         }
-        m->m_len = pkt_len + 2;
-        memcpy(m->m_data + 2, pkt, pkt_len);
+        m->m_hdr.mh_len = pkt_len + 2;
+        memcpy(m->m_hdr.mh_data + 2, pkt, pkt_len);
 
-        m->m_data += 2 + ETH_HLEN;
-        m->m_len -= 2 + ETH_HLEN;
+        m->m_hdr.mh_data += 2 + ETH_HLEN;
+        m->m_hdr.mh_len -= 2 + ETH_HLEN;
 
         ip_input(m);
         break;
@@ -700,9 +700,9 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
     uint8_t buf[1600];
     struct ethhdr *eh = (struct ethhdr *)buf;
     uint8_t ethaddr[ETH_ALEN];
-    const struct ip *iph = (const struct ip *)ifm->m_data;
+    const struct ip *iph = (const struct ip *)ifm->m_hdr.mh_data;
 
-    if (ifm->m_len + ETH_HLEN > sizeof(buf)) {
+    if (ifm->m_hdr.mh_len + ETH_HLEN > sizeof(buf)) {
         return 1;
     }
 
@@ -749,8 +749,8 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
         /* XXX: not correct */
         memcpy(&eh->h_source[2], &slirp->vhost_addr, 4);
         eh->h_proto = htons(ETH_P_IP);
-        memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
-        slirp_output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
+        memcpy(buf + sizeof(struct ethhdr), ifm->m_hdr.mh_data, ifm->m_hdr.mh_len);
+        slirp_output(slirp->opaque, buf, ifm->m_hdr.mh_len + ETH_HLEN);
         return 1;
     }
 }
slirp/socket.c +6 -6
index 77b0c98..f59c403 100644
@@ -478,7 +478,7 @@ sorecvfrom(struct socket *so)
 	  if (!m) {
 	      return;
 	  }
-	  m->m_data += IF_MAXLINKHDR;
+	  m->m_hdr.mh_data += IF_MAXLINKHDR;
 
 	  /*
 	   * XXX Shouldn't FIONREAD packets destined for port 53,
@@ -489,17 +489,17 @@ sorecvfrom(struct socket *so)
 	  ioctlsocket(so->s, FIONREAD, &n);
 
 	  if (n > len) {
-	    n = (m->m_data - m->m_dat) + m->m_len + n + 1;
+	    n = (m->m_hdr.mh_data - m->M_dat.m_dat_) + m->m_hdr.mh_len + n + 1;
 	    m_inc(m, n);
 	    len = M_FREEROOM(m);
 	  }
 	  /* } */
 
-	  m->m_len = recvfrom(so->s, m->m_data, len, 0,
+	  m->m_hdr.mh_len = recvfrom(so->s, m->m_hdr.mh_data, len, 0,
 			      (struct sockaddr *)&addr, &addrlen);
 	  DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
-		      m->m_len, errno,strerror(errno)));
-	  if(m->m_len<0) {
+		      m->m_hdr.mh_len, errno,strerror(errno)));
+	  if(m->m_hdr.mh_len<0) {
 	    u_char code=ICMP_UNREACH_PORT;
 
 	    if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
@@ -562,7 +562,7 @@ sosendto(struct socket *so, struct mbuf *m)
 	DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)));
 
 	/* Don't care what port we get */
-	ret = sendto(so->s, m->m_data, m->m_len, 0,
+	ret = sendto(so->s, m->m_hdr.mh_data, m->m_hdr.mh_len, 0,
 		     (struct sockaddr *)&addr, sizeof (struct sockaddr));
 	if (ret < 0)
 		return -1;
slirp/tcp_input.c +9 -9
index 942aaf4..f740978 100644
@@ -313,8 +313,8 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
 	/*
 	 * Drop TCP, IP headers and TCP options.
 	 */
-	m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
-	m->m_len  -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+	m->m_hdr.mh_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+	m->m_hdr.mh_len  -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
 
     if (slirp->restricted) {
         for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
@@ -592,8 +592,8 @@ findso:
 	      HTONL(ti->ti_ack);
 	      HTONS(ti->ti_win);
 	      HTONS(ti->ti_urp);
-	      m->m_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
-	      m->m_len  += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+	      m->m_hdr.mh_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+	      m->m_hdr.mh_len  += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
 	      *ip=save_ip;
 	      icmp_error(m, ICMP_UNREACH,code, 0,strerror(errno));
 	    }
@@ -1342,18 +1342,18 @@ tcp_pulloutofband(so, ti, m)
 	int cnt = ti->ti_urp - 1;
 
 	while (cnt >= 0) {
-		if (m->m_len > cnt) {
+		if (m->m_hdr.mh_len > cnt) {
 			char *cp = mtod(m, caddr_t) + cnt;
 			struct tcpcb *tp = sototcpcb(so);
 
 			tp->t_iobc = *cp;
 			tp->t_oobflags |= TCPOOB_HAVEDATA;
-			memcpy(sp, cp+1, (unsigned)(m->m_len - cnt - 1));
-			m->m_len--;
+			memcpy(sp, cp+1, (unsigned)(m->m_hdr.mh_len - cnt - 1));
+			m->m_hdr.mh_len--;
 			return;
 		}
-		cnt -= m->m_len;
-		m = m->m_next; /* XXX WRONG! Fix it! */
+		cnt -= m->m_hdr.mh_len;
+		m = m->m_hdr.mh_next; /* XXX WRONG! Fix it! */
 		if (m == 0)
 			break;
 	}
slirp/tcp_output.c +7 -7
index 779314b..269b642 100644
@@ -295,11 +295,11 @@ send:
 			error = 1;
 			goto out;
 		}
-		m->m_data += IF_MAXLINKHDR;
-		m->m_len = hdrlen;
+		m->m_hdr.mh_data += IF_MAXLINKHDR;
+		m->m_hdr.mh_len = hdrlen;
 
 		sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen);
-		m->m_len += len;
+		m->m_hdr.mh_len += len;
 
 		/*
 		 * If we're sending everything we've got, set PUSH.
@@ -315,8 +315,8 @@ send:
 			error = 1;
 			goto out;
 		}
-		m->m_data += IF_MAXLINKHDR;
-		m->m_len = hdrlen;
+		m->m_hdr.mh_data += IF_MAXLINKHDR;
+		m->m_hdr.mh_len = hdrlen;
 	}
 
 	ti = mtod(m, struct tcpiphdr *);
@@ -444,11 +444,11 @@ send:
 	 * to handle ttl and tos; we could keep them in
 	 * the template, but need a way to checksum without them.
 	 */
-	m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
+	m->m_hdr.mh_len = hdrlen + len; /* XXX Needed? m_hdr.mh_len should be correct */
 
     {
 
-	((struct ip *)ti)->ip_len = m->m_len;
+	((struct ip *)ti)->ip_len = m->m_hdr.mh_len;
 
 	((struct ip *)ti)->ip_ttl = IPDEFTTL;
 	((struct ip *)ti)->ip_tos = so->so_iptos;
slirp/tcp_subr.c +31 -31

149 lines not on this page · raw message

slirp/tftp.c +19 -19
index b78765f..5ed5882 100644
@@ -129,11 +129,11 @@ static int tftp_send_oack(struct tftp_session *spt,
     if (!m)
 	return -1;
 
-    memset(m->m_data, 0, m->m_size);
+    memset(m->m_hdr.mh_data, 0, m->m_hdr.mh_size);
 
-    m->m_data += IF_MAXLINKHDR;
-    tp = (void *)m->m_data;
-    m->m_data += sizeof(struct udpiphdr);
+    m->m_hdr.mh_data += IF_MAXLINKHDR;
+    tp = (void *)m->m_hdr.mh_data;
+    m->m_hdr.mh_data += sizeof(struct udpiphdr);
 
     tp->tp_op = htons(TFTP_OACK);
     n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
@@ -147,7 +147,7 @@ static int tftp_send_oack(struct tftp_session *spt,
     daddr.sin_addr = spt->client_ip;
     daddr.sin_port = spt->client_port;
 
-    m->m_len = sizeof(struct tftp_t) - 514 + n -
+    m->m_hdr.mh_len = sizeof(struct tftp_t) - 514 + n -
         sizeof(struct ip) - sizeof(struct udphdr);
     udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
 
@@ -168,11 +168,11 @@ static void tftp_send_error(struct tftp_session *spt,
     goto out;
   }
 
-  memset(m->m_data, 0, m->m_size);
+  memset(m->m_hdr.mh_data, 0, m->m_hdr.mh_size);
 
-  m->m_data += IF_MAXLINKHDR;
-  tp = (void *)m->m_data;
-  m->m_data += sizeof(struct udpiphdr);
+  m->m_hdr.mh_data += IF_MAXLINKHDR;
+  tp = (void *)m->m_hdr.mh_data;
+  m->m_hdr.mh_data += sizeof(struct udpiphdr);
 
   tp->tp_op = htons(TFTP_ERROR);
   tp->x.tp_error.tp_error_code = htons(errorcode);
@@ -184,7 +184,7 @@ static void tftp_send_error(struct tftp_session *spt,
   daddr.sin_addr = spt->client_ip;
   daddr.sin_port = spt->client_port;
 
-  m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) -
+  m->m_hdr.mh_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) -
         sizeof(struct ip) - sizeof(struct udphdr);
 
   udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
@@ -212,11 +212,11 @@ static int tftp_send_data(struct tftp_session *spt,
     return -1;
   }
 
-  memset(m->m_data, 0, m->m_size);
+  memset(m->m_hdr.mh_data, 0, m->m_hdr.mh_size);
 
-  m->m_data += IF_MAXLINKHDR;
-  tp = (void *)m->m_data;
-  m->m_data += sizeof(struct udpiphdr);
+  m->m_hdr.mh_data += IF_MAXLINKHDR;
+  tp = (void *)m->m_hdr.mh_data;
+  m->m_hdr.mh_data += sizeof(struct udpiphdr);
 
   tp->tp_op = htons(TFTP_DATA);
   tp->x.tp_data.tp_block_nr = htons(block_nr);
@@ -239,7 +239,7 @@ static int tftp_send_data(struct tftp_session *spt,
     return -1;
   }
 
-  m->m_len = sizeof(struct tftp_t) - (512 - nobytes) -
+  m->m_hdr.mh_len = sizeof(struct tftp_t) - (512 - nobytes) -
         sizeof(struct ip) - sizeof(struct udphdr);
 
   udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
@@ -404,19 +404,19 @@ static void tftp_handle_error(Slirp *slirp, struct tftp_t *tp, int pktlen)
 
 void tftp_input(struct mbuf *m)
 {
-  struct tftp_t *tp = (struct tftp_t *)m->m_data;
+  struct tftp_t *tp = (struct tftp_t *)m->m_hdr.mh_data;
 
   switch(ntohs(tp->tp_op)) {
   case TFTP_RRQ:
-    tftp_handle_rrq(m->slirp, tp, m->m_len);
+    tftp_handle_rrq(m->slirp, tp, m->m_hdr.mh_len);
     break;
 
   case TFTP_ACK:
-    tftp_handle_ack(m->slirp, tp, m->m_len);
+    tftp_handle_ack(m->slirp, tp, m->m_hdr.mh_len);
     break;
 
   case TFTP_ERROR:
-    tftp_handle_error(m->slirp, tp, m->m_len);
+    tftp_handle_error(m->slirp, tp, m->m_hdr.mh_len);
     break;
   }
 }
slirp/udp.c +13 -13
index 5b060f3..3035e4f 100644
@@ -49,8 +49,8 @@ udp_init(Slirp *slirp)
     slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb;
     slirp->udp_last_so = &slirp->udb;
 }
-/* m->m_data  points at ip packet header
- * m->m_len   length ip packet
+/* m->m_hdr.mh_data  points at ip packet header
+ * m->m_hdr.mh_len   length ip packet
  * ip->ip_len length data (IPDU)
  */
 void
@@ -198,15 +198,15 @@ udp_input(register struct mbuf *m, int iphlen)
         so->so_fport = uh->uh_dport; /* XXX */
 
 	iphlen += sizeof(struct udphdr);
-	m->m_len -= iphlen;
-	m->m_data += iphlen;
+	m->m_hdr.mh_len -= iphlen;
+	m->m_hdr.mh_data += iphlen;
 
 	/*
 	 * Now we sendto() the packet.
 	 */
 	if(sosendto(so,m) == -1) {
-	  m->m_len += iphlen;
-	  m->m_data -= iphlen;
+	  m->m_hdr.mh_len += iphlen;
+	  m->m_hdr.mh_data -= iphlen;
 	  *ip=save_ip;
 	  DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
 	  icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
@@ -215,8 +215,8 @@ udp_input(register struct mbuf *m, int iphlen)
 	m_free(so->so_m);   /* used for ICMP if error on sorecvfrom */
 
 	/* restore the orig mbuf packet */
-	m->m_len += iphlen;
-	m->m_data -= iphlen;
+	m->m_hdr.mh_len += iphlen;
+	m->m_hdr.mh_data -= iphlen;
 	*ip=save_ip;
 	so->so_m=m;         /* ICMP backup */
 
@@ -242,8 +242,8 @@ int udp_output2(struct socket *so, struct mbuf *m,
 	/*
 	 * Adjust for header
 	 */
-	m->m_data -= sizeof(struct udpiphdr);
-	m->m_len += sizeof(struct udpiphdr);
+	m->m_hdr.mh_data -= sizeof(struct udpiphdr);
+	m->m_hdr.mh_len += sizeof(struct udpiphdr);
 
 	/*
 	 * Fill in mbuf with extended UDP header
@@ -253,7 +253,7 @@ int udp_output2(struct socket *so, struct mbuf *m,
     memset(&ui->ui_i.ih_mbuf, 0 , sizeof(struct mbuf_ptr));
 	ui->ui_x1 = 0;
 	ui->ui_pr = IPPROTO_UDP;
-	ui->ui_len = htons(m->m_len - sizeof(struct ip));
+	ui->ui_len = htons(m->m_hdr.mh_len - sizeof(struct ip));
 	/* XXXXX Check for from-one-location sockets, or from-any-location sockets */
         ui->ui_src = saddr->sin_addr;
 	ui->ui_dst = daddr->sin_addr;
@@ -265,9 +265,9 @@ int udp_output2(struct socket *so, struct mbuf *m,
 	 * Stuff checksum and output datagram.
 	 */
 	ui->ui_sum = 0;
-	if ((ui->ui_sum = cksum(m, m->m_len)) == 0)
+	if ((ui->ui_sum = cksum(m, m->m_hdr.mh_len)) == 0)
 		ui->ui_sum = 0xffff;
-	((struct ip *)ui)->ip_len = m->m_len;
+	((struct ip *)ui)->ip_len = m->m_hdr.mh_len;
 
 	((struct ip *)ui)->ip_ttl = IPDEFTTL;
 	((struct ip *)ui)->ip_tos = iptos;
Signature · 1 line
1.7.9.111.gf3fb0
#1 lore raw
Quoted 18 lines · Michael S. Tsirkin

Remove ugly macros for field names,
change done by the following script:

s#\bifq_prev\b#m_prev#g;
s#\bifq_next\b#m_next#g;
s#\bifs_prev\b#m_prevpkt#g;
s#\bifs_next\b#m_nextpkt#g;
s#\bifq_so\b#m_so#g;
s#\bm_next\b#m_hdr.mh_next#g;
s#\bm_prev\b#m_hdr.mh_prev#g;
s#\bm_nextpkt\b#m_hdr.mh_nextpkt#g;
s#\bm_prevpkt\b#m_hdr.mh_prevpkt#g;
s#\bm_flags\b#m_hdr.mh_flags#g;
s#\bm_len\b#m_hdr.mh_len#g;
s#\bm_data\b#m_hdr.mh_data#g;
s#\bm_size\b#m_hdr.mh_size#g;
s#\bm_dat\b#M_dat.m_dat_#g;
s#\bm_ext\b#M_dat.m_ext_#g;

Could you convert M_dat to m_dat as well (do not script, it's also a type)? It looks strange.

Thanks in any case!
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#2 lore raw

Am 15.02.2012 19:55, schrieb Jan Kiszka:

Quoted 20 lines · Michael S. Tsirkin
Quoted 18 lines

Remove ugly macros for field names,
change done by the following script:

s#\bifq_prev\b#m_prev#g;
s#\bifq_next\b#m_next#g;
s#\bifs_prev\b#m_prevpkt#g;
s#\bifs_next\b#m_nextpkt#g;
s#\bifq_so\b#m_so#g;
s#\bm_next\b#m_hdr.mh_next#g;
s#\bm_prev\b#m_hdr.mh_prev#g;
s#\bm_nextpkt\b#m_hdr.mh_nextpkt#g;
s#\bm_prevpkt\b#m_hdr.mh_prevpkt#g;
s#\bm_flags\b#m_hdr.mh_flags#g;
s#\bm_len\b#m_hdr.mh_len#g;
s#\bm_data\b#m_hdr.mh_data#g;
s#\bm_size\b#m_hdr.mh_size#g;
s#\bm_dat\b#M_dat.m_dat_#g;
s#\bm_ext\b#M_dat.m_ext_#g;

Quoted 2 lines

Could you convert M_dat to m_dat as well (do not script, it's also a type)? It looks strange.

What are all these m_ and mh_ prefixes for struct fields even about? When I have an mbuf, I know perfectly well that it is one, and that m_hdr is a header of it.

So while we're cleaning up here, wouldn't mbuf->hdr->next make more sense than mbuf->m_hdr->mh_next?

Kevin

#3 lore raw
Quoted 3 lines · Kevin Wolf

What are all these m_ and mh_ prefixes for struct fields even about? When I have an mbuf, I know perfectly well that it is one, and that m_hdr is a header of it.

That's the dead hand of Sixth Edition Unix and its C compiler that put all struct fields in a single namespace...

-- PMM

#4 lore raw

Am 16.02.2012 12:09, schrieb Peter Maydell:

Quoted 7 lines · Kevin Wolf
Quoted 3 lines

What are all these m_ and mh_ prefixes for struct fields even about? When I have an mbuf, I know perfectly well that it is one, and that m_hdr is a header of it.

That's the dead hand of Sixth Edition Unix and its C compiler that put all struct fields in a single namespace...

Oh, fun. Things you never wanted to know... ;-)

Kevin

#5 lore raw
In reply to Kevin Wolf
Quoted 24 lines · Kevin Wolf

Am 15.02.2012 19:55, schrieb Jan Kiszka:

Quoted 20 lines · Michael S. Tsirkin
Quoted 18 lines

Remove ugly macros for field names,
change done by the following script:

s#\bifq_prev\b#m_prev#g;
s#\bifq_next\b#m_next#g;
s#\bifs_prev\b#m_prevpkt#g;
s#\bifs_next\b#m_nextpkt#g;
s#\bifq_so\b#m_so#g;
s#\bm_next\b#m_hdr.mh_next#g;
s#\bm_prev\b#m_hdr.mh_prev#g;
s#\bm_nextpkt\b#m_hdr.mh_nextpkt#g;
s#\bm_prevpkt\b#m_hdr.mh_prevpkt#g;
s#\bm_flags\b#m_hdr.mh_flags#g;
s#\bm_len\b#m_hdr.mh_len#g;
s#\bm_data\b#m_hdr.mh_data#g;
s#\bm_size\b#m_hdr.mh_size#g;
s#\bm_dat\b#M_dat.m_dat_#g;
s#\bm_ext\b#M_dat.m_ext_#g;

Quoted 2 lines

Could you convert M_dat to m_dat as well (do not script, it's also a type)? It looks strange.

Quoted 6 lines

What are all these m_ and mh_ prefixes for struct fields even about? When I have an mbuf, I know perfectly well that it is one, and that m_hdr is a header of it.

So while we're cleaning up here, wouldn't mbuf->hdr->next make more sense than mbuf->m_hdr->mh_next?

I tend to agree - as we are already touching so many files, and the names also get longer due to this. Mind to respin the series?

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#6 lore raw
In reply to Jan Kiszka
Quoted 20 lines · Jan Kiszka
Quoted 18 lines · Michael S. Tsirkin

Remove ugly macros for field names,
change done by the following script:

s#\bifq_prev\b#m_prev#g;
s#\bifq_next\b#m_next#g;
s#\bifs_prev\b#m_prevpkt#g;
s#\bifs_next\b#m_nextpkt#g;
s#\bifq_so\b#m_so#g;
s#\bm_next\b#m_hdr.mh_next#g;
s#\bm_prev\b#m_hdr.mh_prev#g;
s#\bm_nextpkt\b#m_hdr.mh_nextpkt#g;
s#\bm_prevpkt\b#m_hdr.mh_prevpkt#g;
s#\bm_flags\b#m_hdr.mh_flags#g;
s#\bm_len\b#m_hdr.mh_len#g;
s#\bm_data\b#m_hdr.mh_data#g;
s#\bm_size\b#m_hdr.mh_size#g;
s#\bm_dat\b#M_dat.m_dat_#g;
s#\bm_ext\b#M_dat.m_ext_#g;

Quoted 5 lines

Could you convert M_dat to m_dat as well (do not script, it's also a type)? It looks strange.

Thanks in any case!
Jan

So as you probably saw, that type can be dropped,
then we can script it easily.

Quoted 3 lines
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux