MCPcopy Create free account
hub / github.com/F-Stack/f-stack / memif_socket_create

Function memif_socket_create

dpdk/drivers/net/memif/memif_socket.c:891–986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

889}
890
891static struct memif_socket *
892memif_socket_create(char *key, uint8_t listener, bool is_abstract, uid_t owner_uid, gid_t owner_gid)
893{
894 struct memif_socket *sock;
895 struct sockaddr_un un = { 0 };
896 uint32_t sunlen;
897 int sockfd;
898 int ret;
899 int on = 1;
900
901 sock = rte_zmalloc("memif-socket", sizeof(struct memif_socket), 0);
902 if (sock == NULL) {
903 MIF_LOG(ERR, "Failed to allocate memory for memif socket");
904 return NULL;
905 }
906
907 sock->listener = listener;
908 strlcpy(sock->filename, key, MEMIF_SOCKET_UN_SIZE);
909 TAILQ_INIT(&sock->dev_queue);
910
911 if (listener != 0) {
912 sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
913 if (sockfd < 0)
914 goto error;
915
916 un.sun_family = AF_UNIX;
917 if (is_abstract) {
918 /* abstract address */
919 un.sun_path[0] = '\0';
920 strlcpy(un.sun_path + 1, sock->filename, MEMIF_SOCKET_UN_SIZE - 1);
921 sunlen = RTE_MIN(1 + strlen(sock->filename),
922 MEMIF_SOCKET_UN_SIZE) +
923 sizeof(un) - sizeof(un.sun_path);
924 } else {
925 sunlen = sizeof(un);
926 strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE);
927 }
928
929 ret = setsockopt(sockfd, SOL_SOCKET, SO_PASSCRED, &on,
930 sizeof(on));
931 if (ret < 0)
932 goto error;
933
934 ret = bind(sockfd, (struct sockaddr *)&un, sunlen);
935 if (ret < 0)
936 goto error;
937
938 ret = listen(sockfd, 1);
939 if (ret < 0)
940 goto error;
941
942 MIF_LOG(DEBUG, "Memif listener socket %s created.", sock->filename);
943
944 if (!is_abstract && (owner_uid != (uid_t)-1 || owner_gid != (gid_t)-1)) {
945 ret = chown(sock->filename, owner_uid, owner_gid);
946 if (ret < 0) {
947 MIF_LOG(ERR, "Failed to change listener socket owner");
948 goto error;

Callers 1

memif_socket_initFunction · 0.85

Calls 13

rte_zmallocFunction · 0.85
rte_intr_instance_allocFunction · 0.85
rte_intr_fd_setFunction · 0.85
rte_intr_type_setFunction · 0.85
rte_intr_instance_freeFunction · 0.85
rte_freeFunction · 0.85
strlcpyFunction · 0.50
socketClass · 0.50
setsockoptFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50

Tested by

no test coverage detected