Browse Source

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger 11 years ago
parent
commit
8a0eccb105
3 changed files with 9 additions and 3 deletions
  1. 6 2
      drivers/net/netconsole.c
  2. 2 1
      include/net.h
  3. 1 0
      net/net.c

+ 6 - 2
drivers/net/netconsole.c

@@ -147,13 +147,17 @@ void NcStart(void)
 	}
 }
 
-int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len)
+int nc_input_packet(uchar *pkt, IPaddr_t src_ip, unsigned dest_port,
+	unsigned src_port, unsigned len)
 {
 	int end, chunk;
 
-	if (dest != nc_in_port || !len)
+	if (dest_port != nc_in_port || !len)
 		return 0; /* not for us */
 
+	if (src_ip != nc_ip && !is_broadcast(nc_ip))
+		return 0; /* not from our client */
+
 	debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt);
 
 	if (input_size == sizeof(input_buffer))

+ 2 - 1
include/net.h

@@ -549,7 +549,8 @@ extern void NetReceive(uchar *, int);
 
 #ifdef CONFIG_NETCONSOLE
 void NcStart(void);
-int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
+int nc_input_packet(uchar *pkt, IPaddr_t src_ip, unsigned dest_port,
+	unsigned src_port, unsigned len);
 #endif
 
 static inline __attribute__((always_inline)) int eth_is_on_demand_init(void)

+ 1 - 0
net/net.c

@@ -1161,6 +1161,7 @@ NetReceive(uchar *inpkt, int len)
 
 #ifdef CONFIG_NETCONSOLE
 		nc_input_packet((uchar *)ip + IP_UDP_HDR_SIZE,
+					ntohl(ip->ip_src),
 					ntohs(ip->udp_dst),
 					ntohs(ip->udp_src),
 					ntohs(ip->udp_len) - UDP_HDR_SIZE);