-
Notifications
You must be signed in to change notification settings - Fork 650
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
Simple Berkeley Socket APIs #836
Simple Berkeley Socket APIs #836
Conversation
6388af0
to
6bf86a7
Compare
a48f1e4
to
2dd7004
Compare
It is a simple socket example and related APIs implementation. The goal is to make it easy to compile a C socket program. The first version ignores the capability security model. |
2dd7004
to
862fa16
Compare
c7523d5
to
8088bfc
Compare
3c5dac5
to
23a8cda
Compare
core/iwasm/include/wasm_export.h
Outdated
@@ -337,6 +337,7 @@ wasm_runtime_set_wasi_args_ex(wasm_module_t module, | |||
const char *dir_list[], uint32_t dir_count, | |||
const char *map_dir_list[], uint32_t map_dir_count, | |||
const char *env[], uint32_t env_count, | |||
const char *addr_pool[], uint32_t addr_pool_size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm_runtime_set_wasi_args and wasm_runtime_set_wasi_args_ex should have been used by developers, changing the API will cause compatibility issue. How about introduce new API to set the option? e.g.
void
wasm_runtime_set_wasi_addr_pool(wasm_module_t module,
const char *addr_pool[], uint32_t addr_pool_size);
typedef struct __wasi_addr_ip6_port_t { | ||
__wasi_addr_ip6_t addr; | ||
__wasi_ip_port_t port; | ||
} __wasi_addr_ip6_port_t; | ||
|
||
typedef struct __wasi_addr_t { | ||
__wasi_addr_type_t kind; | ||
union { | ||
__wasi_addr_ip4_port_t ip4; | ||
__wasi_addr_ip6_port_t ip6; | ||
} addr; | ||
} __wasi_addr_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the layout of these structures be same in 32-bit and 64-bit system? Had we tested it in x86-32? If not the same, should add the related padding bytes in the structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing it. Will run more test under x86-32
uint32_t target; | ||
uint32_t address = addr_pool_entry->addr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better use uint32 but not uint32_t here, we usually use uint32/uint16 like types inside runtime, and use uint32_t/uint16_t like types in header files of core/iwasm/include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
|
||
uint32_t mask = addr_pool_entry->mask; | ||
uint32_t first_address = address & mask; | ||
uint32_t last_address = address | (~mask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
uint32_t addr; | ||
uint8_t mask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, had better use uint32 and uint8
product-mini/platforms/posix/main.c
Outdated
/* TODO: parse the configuration file */ | ||
} | ||
else if (!strncmp(argv[0], "--addr-pool=", strlen("--addr-pool="))) { | ||
/* --addr-pool=100.200.244.255/30 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better remove the unused hardcode code
product-mini/platforms/posix/main.c
Outdated
/* --addr-pool=100.200.244.255/30 */ | ||
char *token = NULL; | ||
|
||
if ('\0' == argv[0][13]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be argv[0][12]
ddc5375
to
c5d86a7
Compare
@@ -1969,14 +1969,36 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module, const char *dir_list[], | |||
argc, -1, -1, -1); | |||
} | |||
|
|||
void | |||
wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[], | |||
uint32_t addr_pool_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t to uint32
@@ -731,6 +733,9 @@ wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst, | |||
WASIContext * | |||
wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst); | |||
|
|||
WASM_RUNTIME_API_EXTERN void | |||
wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[], | |||
uint32_t addr_pool_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t to uint32
c5d86a7
to
0fad0ca
Compare
Refer to [WASI PR#459](WebAssembly/WASI#459) Users use `--addr-pool=` to identify an valid ip address range
Reference:
[Networking API design] (WebAssembly/WASI#370)