4
0
Эх сурвалжийг харах

totem: Display IP of sender

To make finding victim of incompatible messages easier, IP of sender is
logged. Propagating IP in layers makes patch slightly larger.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 8 жил өмнө
parent
commit
69857efb5b

+ 22 - 0
exec/totemip.c

@@ -211,6 +211,28 @@ int totemip_localhost_check(const struct totem_ip_address *addr)
 	return totemip_equal(addr, &localhost);
 }
 
+const char *totemip_sa_print(const struct sockaddr *sa)
+{
+	static char buf[INET6_ADDRSTRLEN];
+
+	buf[0] = 0;
+
+	switch (sa->sa_family) {
+	case AF_INET:
+		inet_ntop(sa->sa_family, &((struct sockaddr_in *)(sa))->sin_addr, buf,
+		    INET6_ADDRSTRLEN);
+		break;
+	case AF_INET6:
+		inet_ntop(sa->sa_family, &((struct sockaddr_in6 *)(sa))->sin6_addr, buf,
+		    INET6_ADDRSTRLEN);
+		break;
+	default:
+		return (NULL);
+	}
+
+	return (buf);
+}
+
 const char *totemip_print(const struct totem_ip_address *addr)
 {
 	static char buf[INET6_ADDRSTRLEN];

+ 6 - 3
exec/totemknet.c

@@ -94,7 +94,8 @@ struct totemknet_instance {
 	void (*totemknet_deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len);
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from);
 
 	void (*totemknet_iface_change_fn) (
 		void *context,
@@ -648,7 +649,8 @@ static int data_deliver_fn (
 	instance->totemknet_deliver_fn (
 		instance->context,
 		instance->iov_buffer,
-		msg_len);
+		msg_len,
+		&system_from);
 
 	return (0);
 }
@@ -777,7 +779,8 @@ int totemknet_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 2 - 1
exec/totemknet.h

@@ -54,7 +54,8 @@ extern int totemknet_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 6 - 4
exec/totemnet.c

@@ -57,9 +57,10 @@ struct transport {
 		void *context,
 
 		void (*deliver_fn) (
-		void *context,
-		const void *msg,
-		unsigned int msg_len),
+			void *context,
+			const void *msg,
+			unsigned int msg_len,
+			const struct sockaddr_storage *system_from),
 
 		void (*iface_change_fn) (
 			void *context,
@@ -307,7 +308,8 @@ int totemnet_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 2 - 1
exec/totemnet.h

@@ -64,7 +64,8 @@ extern int totemnet_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 16 - 10
exec/totemsrp.c

@@ -665,7 +665,8 @@ static const char* gsfrom_to_msg(enum gather_state_from gsfrom);
 void main_deliver_fn (
 	void *context,
 	const void *msg,
-	unsigned int msg_len);
+	unsigned int msg_len,
+	const struct sockaddr_storage *system_from);
 
 void main_iface_change_fn (
 	void *context,
@@ -4617,7 +4618,8 @@ static int message_handler_token_hold_cancel (
 static int check_message_header_validity(
 	void *context,
 	const void *msg,
-	unsigned int msg_len)
+	unsigned int msg_len,
+	const struct sockaddr_storage *system_from)
 {
 	struct totemsrp_instance *instance = context;
 	const struct totem_message_header *message_header = msg;
@@ -4626,8 +4628,8 @@ static int check_message_header_validity(
 
 	if (msg_len < sizeof (struct totem_message_header)) {
 		log_printf (instance->totemsrp_log_level_security,
-			    "Received message is too short...  Ignoring %u.",
-			    (unsigned int)msg_len);
+			    "Message received from %s is too short...  Ignoring %u.",
+			    totemip_sa_print((struct sockaddr *)system_from), (unsigned int)msg_len);
 		return (-1);
 	}
 
@@ -4675,7 +4677,8 @@ static int check_message_header_validity(
 		}
 
 		log_printf(instance->totemsrp_log_level_security,
-		    "Received message with bad magic number (probably sent by %s).. Ignoring",
+		    "Message received from %s has bad magic number (probably sent by %s).. Ignoring",
+		    totemip_sa_print((struct sockaddr *)system_from),
 		    guessed_str);
 
 		return (-1);
@@ -4683,8 +4686,9 @@ static int check_message_header_validity(
 
 	if (message_header->version != TOTEM_MH_VERSION) {
 		log_printf(instance->totemsrp_log_level_security,
-		"Received message with unsupported version %u... Ignoring",
-		message_header->version);
+		    "Message received from %s has unsupported version %u... Ignoring",
+		    totemip_sa_print((struct sockaddr *)system_from),
+		    message_header->version);
 
 		return (-1);
 	}
@@ -4696,12 +4700,13 @@ static int check_message_header_validity(
 void main_deliver_fn (
 	void *context,
 	const void *msg,
-	unsigned int msg_len)
+	unsigned int msg_len,
+	const struct sockaddr_storage *system_from)
 {
 	struct totemsrp_instance *instance = context;
 	const struct totem_message_header *message_header = msg;
 
-	if (check_message_header_validity(context, msg, msg_len) == -1) {
+	if (check_message_header_validity(context, msg, msg_len, system_from) == -1) {
 		return ;
 	}
 
@@ -4726,7 +4731,8 @@ void main_deliver_fn (
 		break;
 	default:
 		log_printf (instance->totemsrp_log_level_security,
-		    "Type of received message is wrong...  ignoring %d.\n",
+		    "Message received from %s has wrong type...  ignoring %d.\n",
+		    totemip_sa_print((struct sockaddr *)system_from),
 		    (int)message_header->type);
 
 		instance->stats.rx_msg_dropped++;

+ 6 - 3
exec/totemudp.c

@@ -113,7 +113,8 @@ struct totemudp_instance {
 	void (*totemudp_deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len);
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from);
 
 	void (*totemudp_iface_change_fn) (
 		void *context,
@@ -493,7 +494,8 @@ static int net_deliver_fn (
 	instance->totemudp_deliver_fn (
 		instance->context,
 		iovec->iov_base,
-		iovec->iov_len);
+		iovec->iov_len,
+		&system_from);
 
 	iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX;
 	return (0);
@@ -1137,7 +1139,8 @@ int totemudp_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 2 - 1
exec/totemudp.h

@@ -54,7 +54,8 @@ extern int totemudp_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 6 - 3
exec/totemudpu.c

@@ -103,7 +103,8 @@ struct totemudpu_instance {
 	void (*totemudpu_deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len);
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from);
 
 	void (*totemudpu_iface_change_fn) (
 		void *context,
@@ -472,7 +473,8 @@ static int net_deliver_fn (
 	instance->totemudpu_deliver_fn (
 		instance->context,
 		iovec->iov_base,
-		iovec->iov_len);
+		iovec->iov_len,
+		&system_from);
 
 	iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX;
 	return (0);
@@ -781,7 +783,8 @@ int totemudpu_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 2 - 1
exec/totemudpu.h

@@ -54,7 +54,8 @@ extern int totemudpu_initialize (
 	void (*deliver_fn) (
 		void *context,
 		const void *msg,
-		unsigned int msg_len),
+		unsigned int msg_len,
+		const struct sockaddr_storage *system_from),
 
 	void (*iface_change_fn) (
 		void *context,

+ 1 - 0
include/corosync/totem/totemip.h

@@ -88,6 +88,7 @@ extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,
 int totemip_localhost(int family, struct totem_ip_address *localhost);
 extern int totemip_localhost_check(const struct totem_ip_address *addr);
 extern const char *totemip_print(const struct totem_ip_address *addr);
+extern const char *totemip_sa_print(const struct sockaddr *sa);
 extern int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
 					       struct totem_ip_address *ip_addr);
 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,