Skip to content
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

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

lum1n0us
Copy link
Collaborator

Reference:
[Networking API design] (WebAssembly/WASI#370)

@lum1n0us lum1n0us changed the base branch from main to dev/socket_api November 15, 2021 08:48
@lum1n0us lum1n0us force-pushed the network_api branch 3 times, most recently from 6388af0 to 6bf86a7 Compare November 18, 2021 10:13
@lum1n0us lum1n0us changed the title [WIP] Network APIs [WIP] Simple Berkeley Socket APIs Nov 19, 2021
@lum1n0us lum1n0us force-pushed the network_api branch 2 times, most recently from a48f1e4 to 2dd7004 Compare December 30, 2021 05:53
@lum1n0us
Copy link
Collaborator Author

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.

@lum1n0us lum1n0us force-pushed the network_api branch 2 times, most recently from c7523d5 to 8088bfc Compare January 28, 2022 01:47
@lum1n0us lum1n0us force-pushed the network_api branch 3 times, most recently from 3c5dac5 to 23a8cda Compare February 17, 2022 06:56
@lum1n0us lum1n0us changed the title [WIP] Simple Berkeley Socket APIs Simple Berkeley Socket APIs Feb 17, 2022
core/iwasm/common/wasm_runtime_common.c Show resolved Hide resolved
@@ -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,
Copy link
Contributor

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);

core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c Outdated Show resolved Hide resolved
core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c Outdated Show resolved Hide resolved
Comment on lines +586 to +597
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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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

core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c Outdated Show resolved Hide resolved
Comment on lines 3163 to 3164
uint32_t target;
uint32_t address = addr_pool_entry->addr;
Copy link
Contributor

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

Copy link
Collaborator Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines 52 to 53
uint32_t addr;
uint8_t mask;
Copy link
Contributor

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

/* TODO: parse the configuration file */
}
else if (!strncmp(argv[0], "--addr-pool=", strlen("--addr-pool="))) {
/* --addr-pool=100.200.244.255/30 */
Copy link
Contributor

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

/* --addr-pool=100.200.244.255/30 */
char *token = NULL;

if ('\0' == argv[0][13])
Copy link
Contributor

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]

@lum1n0us lum1n0us force-pushed the network_api branch 3 times, most recently from ddc5375 to c5d86a7 Compare February 22, 2022 06:35
@@ -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)
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint32_t to uint32

@wenyongh wenyongh merged commit d4fc644 into bytecodealliance:dev/socket_api Feb 23, 2022
Refer to [WASI PR#459](WebAssembly/WASI#459)

Users use `--addr-pool=` to identify an valid ip address range
@lum1n0us lum1n0us deleted the network_api branch May 10, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants