[netfilter-cvslog] r3769 - branches/netfilter-ha/linux-2.6-actact/ct_sync

laforge at netfilter.org laforge at netfilter.org
Mon Mar 7 16:09:45 CET 2005


Author: laforge at netfilter.org
Date: 2005-03-07 16:09:45 +0100 (Mon, 07 Mar 2005)
New Revision: 3769

Modified:
   branches/netfilter-ha/linux-2.6-actact/ct_sync/ct_sync_proto.c
Log:
- use recfrom/sendto 
- send retransmissions over unicast


Modified: branches/netfilter-ha/linux-2.6-actact/ct_sync/ct_sync_proto.c
===================================================================
--- branches/netfilter-ha/linux-2.6-actact/ct_sync/ct_sync_proto.c	2005-03-07 15:08:05 UTC (rev 3768)
+++ branches/netfilter-ha/linux-2.6-actact/ct_sync/ct_sync_proto.c	2005-03-07 15:09:45 UTC (rev 3769)
@@ -2,7 +2,7 @@
  * Connection tracking state replication for Netfilter
  *
  * (C) 2002-2004, KOVACS Krisztian <hidden at sch.bme.hu>
- * (C) 2003-2004, Harald Welte <laforge at netfilter.org>
+ * (C) 2003-2005, Harald Welte <laforge at netfilter.org>
  * (C) 2004, BalaBit IT Ltd. <www.balabit.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -58,6 +58,8 @@
 };
 
 struct cts_protoh {
+	/* I. Common part for master and slave */
+
 	/* tx and rx sockets */
 	struct cts_proto_sock send;
 	struct cts_proto_sock recv;
@@ -69,14 +71,19 @@
 				    enum cts_proto_state,
 				    void *);
 	void *transition_callback_data;
-	/* timestamp of last initsync request */
-	unsigned long last_initsync;
+
+	/* II. Master Part */
+
+	/* III. Slave Part */
+
 	/* recovery state of the node */
 	struct {
 		atomic_t active;
 		__u16 seq;
 		int diff;
 	} recovery_request;
+	/* timestamp of last initsync request */
+	unsigned long last_initsync;
 };
 
 static const char *cts_proto_statenames[0x15] = {
@@ -380,7 +387,8 @@
 	pkt.ma.upsince = htonl(jiffies);
 	pkt.ma.flags = 0;
 
-	len = cts_sock_send(cph->send.socket, (char *)&pkt, sizeof(pkt));
+	len = cts_sock_sendto(cph->send.socket, (char *)&pkt, sizeof(pkt),
+			      NULL, 0);
 	if (unlikely(len < sizeof(pkt))) {
 		CT_SYNC_ERR("Send failed, returned %d.\n", len);
 		CT_SYNC_LEAVE();
@@ -444,7 +452,8 @@
 	memset(&pkt, 0, sizeof(pkt));
 	csb_hdr_fill(cph, &pkt.hdr, CT_SYNC_PKT_INITSYNC_FOLLOWS, 0);
 
-	len = cts_sock_send(cph->send.socket, (unsigned char *)&pkt, sizeof(pkt));
+	len = cts_sock_sendto(cph->send.socket, (unsigned char *)&pkt, 
+			      sizeof(pkt), NULL, 0);
 	if (unlikely(len < sizeof(pkt))) {
 		CT_SYNC_ERR("Send failed, returned %d.\n", len);
 		CT_SYNC_LEAVE();
@@ -475,7 +484,8 @@
 	memset(&pkt, 0, sizeof(pkt));
 	csb_hdr_fill(cph, &pkt.hdr, CT_SYNC_PKT_SLAVE_INITSYNC, 0);
 
-	len = cts_sock_send(cph->send.socket, (unsigned char*)&pkt, sizeof(pkt));
+	len = cts_sock_sendto(cph->send.socket, (unsigned char*)&pkt,
+			      sizeof(pkt), NULL, 0);
 	if (unlikely(len < sizeof(pkt))) {
 		CT_SYNC_ERR("Send failed, only sent %d of %u.\n",
 			    len, sizeof(pkt));
@@ -722,8 +732,8 @@
 		csb->pkt.hdr.pktseq = htons(cph->send.ring.seqno++);
 		/* send packet */
 		CT_SYNC_DEBUG2("sending csb=%p, len=%u\n", csb, csb_len(csb));
-		len = cts_sock_send(cph->send.socket, (char *) &csb->pkt, 
-				    csb_len(csb));
+		len = cts_sock_sendto(cph->send.socket, (char *) &csb->pkt, 
+				      csb_len(csb), NULL, 0);
 		if (len < csb_len(csb)) {
 			CT_SYNC_ERR("short send: %d\n", len);
 			CT_SYNC_LEAVE();
@@ -772,7 +782,7 @@
  * chance to recover, initiate a full re-synchronization. Otherwise resend
  * missing packets.
  *
- * Because cts_sock_send() may sleep, we have to do this in two steps:
+ * Because cts_sock_sendto() may sleep, we have to do this in two steps:
  *   - we have to duplicate each csb to be sent with the spinlock of the ring
  *     held
  *   - walk the list of our duplicated buffers and send each csb
@@ -782,7 +792,8 @@
  *   0 otherwise
  */
 static int
-cts_proto_recover(struct cts_protoh *cph, const u16 seq) 
+cts_proto_recover(struct cts_protoh *cph, const u16 seq,
+		  struct sockaddr_storage *ss) 
 { 
 	struct csb_ring *csr = &cph->send.ring;
 	struct list_head *i, *t, q;
@@ -843,8 +854,9 @@
 		CTS_STAT_INC(tx.pkts_recover);
 
 		/* resend packet */
-		ssize_t len = cts_sock_send(cph->send.socket, (char *) &csb->pkt, 
-					csb_len(csb));
+		ssize_t len = cts_sock_sendto(cph->send.socket, 
+					      (char *) &csb->pkt, csb_len(csb),
+					      ss, sizeof(*ss));
 		if (unlikely(len < csb_len(csb))) {
 			CT_SYNC_ERR("error during retransmit: %d\n", len);
 		}
@@ -906,8 +918,9 @@
 	memset(&hdr, 0, sizeof(hdr));
 	csb_hdr_fill(cph, &hdr, CT_SYNC_PKT_NACK, seq);
 
-	len = cts_sock_send(cph->send.socket, (char *)&hdr, 
-			    sizeof(struct ct_sync_pkthdr));
+	len = cts_sock_sendto(cph->send.socket, (char *)&hdr, 
+			      sizeof(struct ct_sync_pkthdr),
+			      NULL, 0);
 	if (unlikely(len < sizeof(struct ct_sync_pkthdr))) {
 		CT_SYNC_ERR("Send failed, returned %d.\n", len);
 		CT_SYNC_LEAVE();
@@ -1000,7 +1013,8 @@
 	}
 
 	/* receive packet */
-	len = cts_sock_recv(cph->recv.socket, (char *)&csb->pkt, csb_size(csb));
+	len = cts_sock_recvfrom(cph->recv.socket, (char *)&csb->pkt, 
+				csb_size(csb), &csb->addr, sizeof(csb->addr));
 	if (unlikely(len < sizeof(struct ct_sync_pkthdr))) {
 		CT_SYNC_ERR("short packet, %d < %u\n", len,
 				sizeof(struct ct_sync_pkthdr));
@@ -1093,7 +1107,8 @@
 		/* free spinlock early to avoid deadlock with send lock */
 		spin_unlock(&csr->lock);
 		/* try to recover and request full resync if failed */
-		if (cts_proto_recover(cph, recover_seq) < 0)
+		if (cts_proto_recover(cph, recover_seq, &csb->addr, 
+				      sizeof(csb->addr)) < 0)
 			ret = CTS_PROTO_RCV_INITSYNC;
 		else
 			ret = CTS_PROTO_RCV_NACK;
@@ -1304,7 +1319,7 @@
 /* initialize protocol */
 struct cts_protoh *
 cts_proto_init(char *devname, 
-	       const struct sockaddr_in *addr, 
+	       const struct sockaddr_storage *addr, 
 	       void (*transition_callback)(struct cts_protoh*,
 					   enum cts_proto_state,
 					   enum cts_proto_state,




More information about the netfilter-cvslog mailing list