Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
ad99c016
Commit
ad99c016
authored
Nov 10, 2015
by
Terry Ellison
Browse files
Merge pull request #729 from DiUS/tcp-port-rand
Fix to do TCP port number randomization at boot.
parents
0e558262
f82415f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/lwip/core/tcp.c
View file @
ad99c016
...
@@ -635,7 +635,7 @@ tcp_new_port(void)
...
@@ -635,7 +635,7 @@ tcp_new_port(void)
#define TCP_LOCAL_PORT_RANGE_START 4096
#define TCP_LOCAL_PORT_RANGE_START 4096
#define TCP_LOCAL_PORT_RANGE_END 0x7fff
#define TCP_LOCAL_PORT_RANGE_END 0x7fff
#endif
#endif
static
u16_t
port
=
TCP_LOCAL_PORT_RANGE_START
;
static
u16_t
port
__attribute__
((
section
(
".port"
)))
=
TCP_LOCAL_PORT_RANGE_START
;
again:
again:
if
(
++
port
>=
TCP_LOCAL_PORT_RANGE_END
)
{
if
(
++
port
>=
TCP_LOCAL_PORT_RANGE_END
)
{
...
...
app/user/user_main.c
View file @
ad99c016
...
@@ -51,6 +51,21 @@ void TEXT_SECTION_ATTR user_start_trampoline (void)
...
@@ -51,6 +51,21 @@ void TEXT_SECTION_ATTR user_start_trampoline (void)
}
}
/* To avoid accidentally losing the fix for the TCP port randomization
* during an LWIP upgrade, we've implemented most it outside the LWIP
* source itself. This enables us to test for the presence of the fix
* /at link time/ and error out if it's been lost.
* The fix itself consists of putting the function-static 'port' variable
* into its own section, and get the linker to provide an alias for it.
* From there we can then manually randomize it at boot.
*/
static
inline
void
tcp_random_port_init
(
void
)
{
extern
uint16_t
_tcp_new_port_port
;
// provided by the linker script
_tcp_new_port_port
+=
xthal_get_ccount
()
%
4096
;
}
void
task_lua
(
os_event_t
*
e
){
void
task_lua
(
os_event_t
*
e
){
char
*
lua_argv
[]
=
{
(
char
*
)
"lua"
,
(
char
*
)
"-i"
,
NULL
};
char
*
lua_argv
[]
=
{
(
char
*
)
"lua"
,
(
char
*
)
"-i"
,
NULL
};
NODE_DBG
(
"Task task_lua started.
\n
"
);
NODE_DBG
(
"Task task_lua started.
\n
"
);
...
@@ -145,6 +160,9 @@ void nodemcu_init(void)
...
@@ -145,6 +160,9 @@ void nodemcu_init(void)
// char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL };
// char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL };
// lua_main( 3, lua_argv );
// lua_main( 3, lua_argv );
// NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
// NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
tcp_random_port_init
();
task_init
();
task_init
();
system_os_post
(
LUA_TASK_PRIO
,
SIG_LUA
,
's'
);
system_os_post
(
LUA_TASK_PRIO
,
SIG_LUA
,
's'
);
}
}
...
...
ld/nodemcu.ld
View file @
ad99c016
...
@@ -113,6 +113,15 @@ SECTIONS
...
@@ -113,6 +113,15 @@ SECTIONS
{
{
_data_start = ABSOLUTE(.);
_data_start = ABSOLUTE(.);
*(.data)
*(.data)
/* Hook for randomizing TCP start numbers */
_tcp_new_port_port = ABSOLUTE(.);
*/liblwip.a:tcp.o(.port)
/* Verify that the LWIP source has been patched as needed, or fail with
* a divide by zero error (../ld/nodemcu.ld:xxx / by zero) */
_tcp_new_port_port_size = ABSOLUTE(.) - _tcp_new_port_port;
_ensure_tcp_port_randomization_fix_presence = 1 / _tcp_new_port_port_size;
*(.data.*)
*(.data.*)
*(.gnu.linkonce.d.*)
*(.gnu.linkonce.d.*)
*(.data1)
*(.data1)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment