From f42f6286b490e3b0bcd9855fe3b2f3ffc0f44edf Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 6 Aug 2021 04:34:13 +0000 Subject: [PATCH] added HIO_DEV_SCK_SCTP4 and HIO_DEV_SCK_SCTP6 --- hio/bin/t06.c | 15 ++++++++--- hio/lib/hio-sck.h | 6 +++++ hio/lib/sck.c | 64 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/hio/bin/t06.c b/hio/bin/t06.c index be37ab3..75ff62c 100644 --- a/hio/bin/t06.c +++ b/hio/bin/t06.c @@ -15,6 +15,8 @@ static int g_num_thrs = 2; static hio_svc_htts_t* g_htts[MAX_NUM_THRS]; static int g_htts_no = 0; static pthread_mutex_t g_htts_mutex = PTHREAD_MUTEX_INITIALIZER; +static int g_dev_type4 = HIO_DEV_SCK_TCP4; +static int g_dev_type6 = HIO_DEV_SCK_TCP6; static int print_qparam (hio_bcs_t* key, hio_bcs_t* val, void* ctx) { @@ -477,6 +479,7 @@ static int add_listener (hio_t* hio, hio_bch_t* addrstr) return -1; } bi.options = HIO_DEV_SCK_BIND_REUSEADDR /*| HIO_DEV_SCK_BIND_REUSEPORT |*/; + bi.options = HIO_DEV_SCK_BIND_IGNERR; #if defined(USE_SSL) bi.options |= HIO_DEV_SCK_BIND_SSL; bi.ssl_certfile = "localhost.crt"; @@ -485,8 +488,8 @@ static int add_listener (hio_t* hio, hio_bch_t* addrstr) memset (&mi, 0, HIO_SIZEOF(mi)); f = hio_skad_family(&bi.localaddr); - if (f == HIO_AF_INET) mi.type = HIO_DEV_SCK_TCP4; - else if (f == HIO_AF_INET6) mi.type = HIO_DEV_SCK_TCP6; + if (f == HIO_AF_INET) mi.type = g_dev_type4; + else if (f == HIO_AF_INET6) mi.type = g_dev_type6; else if (f == HIO_AF_UNIX) mi.type = HIO_DEV_SCK_UNIX; else { @@ -553,7 +556,13 @@ int main (int argc, char* argv[]) // TODO: use getopt() or something similar for (i = 1; i < argc; ) { - if (strcmp(argv[i], "-t") == 0) + if (strcmp(argv[i], "-s") == 0) + { + i++; + g_dev_type4 = HIO_DEV_SCK_SCTP4; + g_dev_type6 = HIO_DEV_SCK_SCTP6; + } + else if (strcmp(argv[i], "-t") == 0) { i++; if (i < argc) diff --git a/hio/lib/hio-sck.h b/hio/lib/hio-sck.h index b4d1b65..4e6e4f0 100644 --- a/hio/lib/hio-sck.h +++ b/hio/lib/hio-sck.h @@ -269,6 +269,12 @@ enum hio_dev_sck_type_t HIO_DEV_SCK_UDP4, HIO_DEV_SCK_UDP6, + HIO_DEV_SCK_SCTP4, /* one-to-one sctp stream */ + HIO_DEV_SCK_SCTP6, /* one-to-one sctp stream */ + + HIO_DEV_SCK_SCTP4_SP, /* one-to-one sctp seqpacket */ + HIO_DEV_SCK_SCTP6_SP, /* one-to-one sctp seqpacket */ + /* ICMP at the IPv4 layer */ HIO_DEV_SCK_ICMP4, diff --git a/hio/lib/sck.c b/hio/lib/sck.c index ed04d01..a6910a1 100644 --- a/hio/lib/sck.c +++ b/hio/lib/sck.c @@ -229,58 +229,78 @@ struct sck_type_map_t static struct sck_type_map_t sck_type_map[] = { /* HIO_DEV_SCK_QX */ - { HIO_AF_QX, 0, 0, 0 }, + { HIO_AF_QX, 0, 0, 0 }, #if defined(AF_UNIX) - { AF_UNIX, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, + { AF_UNIX, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, #else - { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, #endif /* HIO_DEV_SCK_TCP4 */ - { AF_INET, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, + { AF_INET, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, /* HIO_DEV_SCK_TCP6 */ - { AF_INET6, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, + { AF_INET6, SOCK_STREAM, 0, HIO_DEV_CAP_STREAM }, /* HIO_DEV_SCK_UPD4 */ - { AF_INET, SOCK_DGRAM, 0, 0 }, + { AF_INET, SOCK_DGRAM, 0, 0 }, /* HIO_DEV_SCK_UDP6 */ - { AF_INET6, SOCK_DGRAM, 0, 0 }, + { AF_INET6, SOCK_DGRAM, 0, 0 }, + +#if defined(IPPROTO_SCTP) + /* HIO_DEV_SCK_SCTP4 */ + { AF_INET, SOCK_STREAM, IPPROTO_SCTP, HIO_DEV_CAP_STREAM }, + + /* HIO_DEV_SCK_SCTP6 */ + { AF_INET6, SOCK_STREAM, IPPROTO_SCTP, HIO_DEV_CAP_STREAM }, + + /* HIO_DEV_SCK_SCTP4_SP - not implemented */ + { -1, SOCK_SEQPACKET, IPPROTO_SCTP, 0 }, + + /* HIO_DEV_SCK_SCTP6_SP - not implemented */ + { -1, SOCK_SEQPACKET, IPPROTO_SCTP, 0 }, +#else + { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, +#endif /* HIO_DEV_SCK_ICMP4 - IP protocol field is 1 byte only. no byte order conversion is needed */ - { AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, }, + { AF_INET, SOCK_RAW, IPPROTO_ICMP, 0 }, /* HIO_DEV_SCK_ICMP6 - IP protocol field is 1 byte only. no byte order conversion is needed */ - { AF_INET6, SOCK_RAW, IPPROTO_ICMP, 0, }, + { AF_INET6, SOCK_RAW, IPPROTO_ICMP, 0 }, + #if defined(AF_PACKET) && (HIO_SIZEOF_STRUCT_SOCKADDR_LL > 0) /* HIO_DEV_SCK_ARP - Ethernet type is 2 bytes long. Protocol must be specified in the network byte order */ - { AF_PACKET, SOCK_RAW, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, + { AF_PACKET, SOCK_RAW, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, /* HIO_DEV_SCK_ARP_DGRAM - link-level header removed*/ - { AF_PACKET, SOCK_DGRAM, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, + { AF_PACKET, SOCK_DGRAM, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, #elif defined(AF_LINK) && (HIO_SIZEOF_STRUCT_SOCKADDR_DL > 0) /* HIO_DEV_SCK_ARP */ - { AF_LINK, SOCK_RAW, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, + { AF_LINK, SOCK_RAW, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, /* HIO_DEV_SCK_ARP_DGRAM */ - { AF_LINK, SOCK_DGRAM, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, + { AF_LINK, SOCK_DGRAM, HIO_CONST_HTON16(HIO_ETHHDR_PROTO_ARP), 0 }, #else - { -1, 0, 0, 0 }, - { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, #endif #if defined(AF_PACKET) && (HIO_SIZEOF_STRUCT_SOCKADDR_LL > 0) /* HIO_DEV_SCK_PACKET */ - { AF_PACKET, SOCK_RAW, HIO_CONST_HTON16(ETH_P_ALL), 0 }, + { AF_PACKET, SOCK_RAW, HIO_CONST_HTON16(ETH_P_ALL), 0 }, #elif defined(AF_LINK) && (HIO_SIZEOF_STRUCT_SOCKADDR_DL > 0) /* HIO_DEV_SCK_PACKET */ - { AF_LINK, SOCK_RAW, HIO_CONST_HTON16(0), 0 }, + { AF_LINK, SOCK_RAW, HIO_CONST_HTON16(0), 0 }, #else - { -1, 0, 0, 0 }, + { -1, 0, 0, 0 }, #endif /* HIO_DEV_SCK_BPF - arp */ @@ -1054,8 +1074,11 @@ static int dev_sck_ioctl (hio_dev_t* dev, int cmd, void* arg) int v = 1; if (setsockopt(rdev->hnd, IPPROTO_IPV6, IPV6_V6ONLY, &v, HIO_SIZEOF(v)) == -1) { - hio_seterrbfmtwithsyserr (hio, 0, errno, "unable to set IPV6_V6ONLY"); - return -1; + if (!(bnd->options & HIO_DEV_SCK_BIND_IGNERR)) + { + hio_seterrbfmtwithsyserr (hio, 0, errno, "unable to set IPV6_V6ONLY"); + return -1; + } } } @@ -1064,6 +1087,7 @@ static int dev_sck_ioctl (hio_dev_t* dev, int cmd, void* arg) int v = 1; if (setsockopt(rdev->hnd, SOL_SOCKET, SO_BROADCAST, &v, HIO_SIZEOF(v)) == -1) { + /* not affected by HIO_DEV_SCK_BIND_IGNERR */ hio_seterrbfmtwithsyserr (hio, 0, errno, "unable to set SO_BROADCAST"); return -1; }