mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
syslog: make the destination port configurable
The port was frozen at 514 in the call that opens the connection, so a collector listening anywhere else was simply out of reach, and plenty do, because 514 is privileged and containerised collectors usually get a high port instead. Working around it meant putting a proxy in front, which then rewrites the source address and hides which device actually sent the line. Add `syslog port <n>`. The default stays 514, so nothing changes for an existing configuration. Setting it tears the connection down and builds a new one, the same dance the address already does, because uip_udp_new() freezes the port into the connection. The value is parsed here rather than through atoi_short(), which reports "no digits" but not overflow: 65540 would quietly wrap to 4 and we would open a connection to a port nobody asked for. Checking before each multiply keeps it in 16-bit arithmetic. Zero then covers all three ways to be wrong - no digits, past 65535, or an explicit "0", which is not a port either. Whitelist the new command in config.js as well, next to `syslog ip`, or the line is dropped without a word when the configuration is saved and the setting quietly fails to survive a reboot. The dedup entry has to precede the general `^syslog\b` one, otherwise it would deduplicate against `syslog on`. itoa_short() is new: itoa() only handles a byte and print_short() prints hex, so there was no way to show a port as a decimal number. Kept separate from itoa() rather than widening it, because every existing caller passes a byte and would start paying for 16-bit divisions it does not need. The scratch variables for the parser live in xdata. Locals there would take internal RAM, and this image has none left: data ends at 0x77, the overlay occupies 0x78-0x7f and the stack starts at 0x80. Measured: no module's DSEG grew.
This commit is contained in:
1 parent
9d4e531306
commit
cb43b3cbd6
6 files changed
+101
-4
No files matched your search
@@ -278,6 +278,32 @@ void itoa(uint8_t v)
|
||||
}
|
||||
|
||||
|
||||
/* Same as itoa(), one decade wider: enough for a port number. Kept separate
|
||||
* rather than widening itoa() itself, because every existing caller passes a
|
||||
* byte and would start paying for 16-bit divisions it does not need. */
|
||||
void itoa_short(uint16_t v)
|
||||
{
|
||||
uint8_t t = v / 10000;
|
||||
uint8_t print_zeros = t;
|
||||
|
||||
if (print_zeros)
|
||||
write_char('0' + t);
|
||||
t = (v / 1000) % 10;
|
||||
print_zeros |= t;
|
||||
if (print_zeros)
|
||||
write_char('0' + t);
|
||||
t = (v / 100) % 10;
|
||||
print_zeros |= t;
|
||||
if (print_zeros)
|
||||
write_char('0' + t);
|
||||
t = (v / 10) % 10;
|
||||
print_zeros |= t;
|
||||
if (print_zeros)
|
||||
write_char('0' + t);
|
||||
write_char('0' + (v % 10));
|
||||
}
|
||||
|
||||
|
||||
void print_string(__code char *p)
|
||||
{
|
||||
while (*p)
|
||||
|
||||
Reference in new issue
Block a user