-
Notifications
You must be signed in to change notification settings - Fork 26
added sntp, dns and updated timer and net_proc #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4fae778
7f366c0
e226f6a
ae6f320
e70b60a
49aae7e
58df756
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,20 @@ | |
| #include "types.h" | ||
| #include "networking/port_manager.h" | ||
| #include "net/internet_layer/ipv4.h" | ||
| #include "math/rng.h" | ||
|
|
||
| static port_entry_t g_port_table[PROTO_COUNT][MAX_PORTS];//tab proto/port | ||
|
|
||
| static inline bool port_valid(uint16_t p) { | ||
| static inline bool port_valid(uint32_t p) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing I removed it again in the update compiler warnings clean up branch. It was disused in the network changes which landed in |
||
| return p > 0 && p < MAX_PORTS; | ||
| } | ||
|
|
||
| static inline bool proto_valid(protocol_t proto) { | ||
| return (uint32_t)proto< PROTO_COUNT; | ||
| return (uint32_t)proto < PROTO_COUNT; | ||
| } | ||
|
|
||
| void port_manager_init() { | ||
| for (int pr = 0; pr < PROTO_COUNT; ++pr) { | ||
| void port_manager_init(void) { | ||
| for (uint32_t pr = 0; pr < PROTO_COUNT; ++pr) { | ||
| for (uint32_t p = 0; p < MAX_PORTS; ++p) { | ||
| g_port_table[pr][p].used = false; | ||
| g_port_table[pr][p].pid = PORT_FREE_OWNER; | ||
|
|
@@ -27,7 +29,18 @@ int port_alloc_ephemeral(protocol_t proto, | |
| port_recv_handler_t handler) | ||
| { | ||
| if (!proto_valid(proto)) return -1; | ||
| for (uint16_t p = PORT_MIN_EPHEMERAL; p <= PORT_MAX_EPHEMERAL; ++p) { | ||
|
|
||
| rng_t rng; | ||
| rng_init_random(&rng); | ||
| uint32_t seed = rng_next32(&rng); | ||
|
|
||
| uint32_t minp = (uint32_t)PORT_MIN_EPHEMERAL; | ||
| uint32_t maxp = (uint32_t)PORT_MAX_EPHEMERAL; | ||
| uint32_t range = maxp - minp + 1u; | ||
| uint32_t first = minp + (seed % range); | ||
|
|
||
| for (uint32_t i = 0; i < range; ++i) { | ||
| uint32_t p = minp + ((first - minp + i) % range); | ||
| port_entry_t *e = &g_port_table[proto][p]; | ||
| if (!e->used) { | ||
| e->used = true; | ||
|
|
@@ -67,8 +80,8 @@ bool port_unbind(protocol_t proto, | |
| } | ||
|
|
||
| void port_unbind_all(uint16_t pid) { | ||
| for (int pr = 0; pr < PROTO_COUNT; ++pr) { | ||
| for (uint16_t p = 1; p < MAX_PORTS; ++p) { | ||
| for (uint32_t pr = 0; pr < PROTO_COUNT; ++pr) { | ||
| for (uint32_t p = 1; p < MAX_PORTS; ++p) { | ||
| port_entry_t *e = &g_port_table[pr][p]; | ||
| if (e->used && e->pid == pid) { | ||
| e->used = false; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.