Commit 7f51898c1b170e0036e6931a17ada46e2b4fd52e
1 parent
ee1f4caaa2
Exists in
master
and in
54 other branches
net: Make netconsole src and dest ports configurable
It is desirable to use different port numbers for sending and receiving packets with netconsole in the case where you have more than one device on the local subnet with netconsole enabled for broadcast. When they use the same port for both, any output from one will look like input to the other. This is typlically not desirable. This patch allows the input and output ports to be specified separately in the environment. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Cc: Mike Frysinger <vapier@gentoo.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
Showing 3 changed files with 34 additions and 16 deletions Side-by-side Diff
doc/README.NetConsole
... | ... | @@ -11,6 +11,9 @@ |
11 | 11 | omitted, the value of 6666 is used. If the env var doesn't exist, the |
12 | 12 | broadcast address and port 6666 are used. If it is set to an IP |
13 | 13 | address of 0 (or 0.0.0.0) then no messages are sent to the network. |
14 | +The source / listening port can be configured separately by setting | |
15 | +the 'ncinport' environment variable and the destination port can be | |
16 | +configured by setting the 'ncoutport' environment variable. | |
14 | 17 | |
15 | 18 | For example, if your server IP is 192.168.1.1, you could use: |
16 | 19 |
drivers/net/netconsole.c
... | ... | @@ -36,7 +36,8 @@ |
36 | 36 | static int net_timeout; |
37 | 37 | static uchar nc_ether[6]; /* server enet address */ |
38 | 38 | static IPaddr_t nc_ip; /* server ip */ |
39 | -static short nc_port; /* source/target port */ | |
39 | +static short nc_out_port; /* target output port */ | |
40 | +static short nc_in_port; /* source input port */ | |
40 | 41 | static const char *output_packet; /* used by first send udp */ |
41 | 42 | static int output_packet_len; |
42 | 43 | |
... | ... | @@ -71,7 +72,7 @@ |
71 | 72 | net_set_arp_handler(nc_wait_arp_handler); |
72 | 73 | pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; |
73 | 74 | memcpy(pkt, output_packet, output_packet_len); |
74 | - NetSendUDPPacket(nc_ether, nc_ip, nc_port, nc_port, | |
75 | + NetSendUDPPacket(nc_ether, nc_ip, nc_out_port, nc_in_port, | |
75 | 76 | output_packet_len); |
76 | 77 | } |
77 | 78 | } |
... | ... | @@ -80,7 +81,7 @@ |
80 | 81 | { |
81 | 82 | int end, chunk; |
82 | 83 | |
83 | - if (dest != nc_port || !len) | |
84 | + if (dest != nc_in_port || !len) | |
84 | 85 | return 0; /* not for us */ |
85 | 86 | |
86 | 87 | debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt); |
... | ... | @@ -139,7 +140,7 @@ |
139 | 140 | memcpy(pkt, buf, len); |
140 | 141 | ether = nc_ether; |
141 | 142 | ip = nc_ip; |
142 | - NetSendUDPPacket(ether, ip, nc_port, nc_port, len); | |
143 | + NetSendUDPPacket(ether, ip, nc_out_port, nc_in_port, len); | |
143 | 144 | |
144 | 145 | if (inited) |
145 | 146 | eth_halt(); |
146 | 147 | |
147 | 148 | |
148 | 149 | |
149 | 150 | |
... | ... | @@ -148,20 +149,30 @@ |
148 | 149 | static int nc_start(void) |
149 | 150 | { |
150 | 151 | int netmask, our_ip; |
152 | + char *p; | |
151 | 153 | |
152 | - nc_port = 6666; /* default port */ | |
154 | + nc_out_port = 6666; /* default port */ | |
155 | + nc_in_port = nc_out_port; | |
153 | 156 | |
154 | 157 | if (getenv("ncip")) { |
155 | - char *p; | |
156 | 158 | |
157 | 159 | nc_ip = getenv_IPaddr("ncip"); |
158 | 160 | if (!nc_ip) |
159 | 161 | return -1; /* ncip is 0.0.0.0 */ |
160 | 162 | p = strchr(getenv("ncip"), ':'); |
161 | - if (p != NULL) | |
162 | - nc_port = simple_strtoul(p + 1, NULL, 10); | |
163 | + if (p != NULL) { | |
164 | + nc_out_port = simple_strtoul(p + 1, NULL, 10); | |
165 | + nc_in_port = nc_out_port; | |
166 | + } | |
163 | 167 | } else |
164 | - nc_ip = ~0; /* ncip is not set */ | |
168 | + nc_ip = ~0; /* ncip is not set, so broadcast */ | |
169 | + | |
170 | + p = getenv("ncoutport"); | |
171 | + if (p != NULL) | |
172 | + nc_out_port = simple_strtoul(p, NULL, 10); | |
173 | + p = getenv("ncinport"); | |
174 | + if (p != NULL) | |
175 | + nc_in_port = simple_strtoul(p, NULL, 10); | |
165 | 176 | |
166 | 177 | our_ip = getenv_IPaddr("ipaddr"); |
167 | 178 | netmask = getenv_IPaddr("netmask"); |
tools/netconsole
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | usage() { |
4 | 4 | ( |
5 | - echo "Usage: $0 <board IP> [board port]" | |
5 | + echo "Usage: $0 <board-IP> [board-port [board-in-port]]" | |
6 | 6 | echo "" |
7 | 7 | echo "If port is not specified, '6666' will be used" |
8 | 8 | [ -z "$*" ] && exit 0 |
9 | 9 | |
... | ... | @@ -24,9 +24,13 @@ |
24 | 24 | done |
25 | 25 | |
26 | 26 | ip=$1 |
27 | -port=${2:-6666} | |
27 | +board_out_port=${2:-6666} | |
28 | +board_in_port=${3:-${board_out_port}} | |
28 | 29 | |
29 | -if [ -z "${ip}" ] || [ -n "$3" ] ; then | |
30 | +echo Board out port: ${board_out_port} | |
31 | +echo Board in port: ${board_in_port} | |
32 | + | |
33 | +if [ -z "${ip}" ] || [ -n "$4" ] ; then | |
30 | 34 | usage "Invalid number of arguments" |
31 | 35 | fi |
32 | 36 | |
33 | 37 | |
34 | 38 | |
35 | 39 | |
... | ... | @@ -41,20 +45,20 @@ |
41 | 45 | ( |
42 | 46 | if type ncb 2>/dev/null ; then |
43 | 47 | # see if ncb is in $PATH |
44 | - exec ncb ${port} | |
48 | + exec ncb ${board_out_port} | |
45 | 49 | |
46 | 50 | elif [ -x ${0%/*}/ncb ] ; then |
47 | 51 | # maybe it's in the same dir as the netconsole script |
48 | - exec ${0%/*}/ncb ${port} | |
52 | + exec ${0%/*}/ncb ${board_out_port} | |
49 | 53 | |
50 | 54 | else |
51 | 55 | # blah, just use regular netcat |
52 | - while ${nc} -u -l -p ${port} < /dev/null ; do | |
56 | + while ${nc} -u -l -p ${board_out_port} < /dev/null ; do | |
53 | 57 | : |
54 | 58 | done |
55 | 59 | fi |
56 | 60 | ) & |
57 | 61 | pid=$! |
58 | -${nc} -u ${ip} ${port} | |
62 | +${nc} -u ${ip} ${board_in_port} | |
59 | 63 | kill ${pid} 2>/dev/null |