[netfilter-cvslog] r4127 - trunk/libnfnetlink

laforge at netfilter.org laforge at netfilter.org
Mon Jul 18 21:13:30 CEST 2005


Author: laforge at netfilter.org
Date: 2005-07-18 21:13:28 +0200 (Mon, 18 Jul 2005)
New Revision: 4127

Modified:
   trunk/libnfnetlink/libnfnetlink.c
Log:
- return error from underyling close() in nfnl_close()
- abord if -EBADF
- return 0 in case of NLMSG_DONE
- use new NLMSG_TAIL macro
- fix alignment (missing NLMSG_ALIGN)
(Pablo Neira)


Modified: trunk/libnfnetlink/libnfnetlink.c
===================================================================
--- trunk/libnfnetlink/libnfnetlink.c	2005-07-18 19:11:45 UTC (rev 4126)
+++ trunk/libnfnetlink/libnfnetlink.c	2005-07-18 19:13:28 UTC (rev 4127)
@@ -108,10 +108,7 @@
  */
 int nfnl_close(struct nfnl_handle *nfnlh)
 {
-	if (nfnlh->fd)
-		close(nfnlh->fd);
-
-	return 0;
+	return close(nfnlh->fd);
 }
 
 /**
@@ -202,6 +199,9 @@
 		if (remain < 0) {
 			if (errno == EINTR)
 				continue;
+			/* Bad file descriptor */
+			if (errno == EBADF)
+				break;
 			nfnl_error("recvmsg overrun");
 			continue;
 		}
@@ -231,7 +231,7 @@
 
 			/* end of messages reached, let's return */
 			if (h->nlmsg_type == NLMSG_DONE)
-				return -100;
+				return 0;
 
 			/* Break the loop if success is explicitely
 			 * reported via NLM_F_ACK flag set */
@@ -400,12 +400,11 @@
 		return -1;
 	}
 
-	nfa = (struct nfattr *)(((char *)n) + NLMSG_ALIGN(n->nlmsg_len));
+	nfa = NLMSG_TAIL(n);
 	nfa->nfa_type = type;
 	nfa->nfa_len = len;
 	memcpy(NFA_DATA(nfa), data, alen);
-	n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + len);
-
+	n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + NFA_ALIGN(len));
 	return 0;
 }
 
@@ -482,7 +481,7 @@
 {
 	while (NFA_OK(nfa, len)) {
 		if (nfa->nfa_type <= max)
-			tb[nfa->nfa_type] = nfa;
+			tb[nfa->nfa_type-1] = nfa;
                 nfa = NFA_NEXT(nfa,len);
 	}
 	if (len)




More information about the netfilter-cvslog mailing list