本文整理汇总了C++中sk_alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ sk_alloc函数的具体用法?C++ sk_alloc怎么用?C++ sk_alloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sk_alloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bnep_sock_create
static int bnep_sock_create(struct socket *sock, int protocol)
{
struct sock *sk;
BT_DBG("sock %p", sock);
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &bnep_proto, 1);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sock->ops = &bnep_sock_ops;
sock->state = SS_UNCONNECTED;
sock_reset_flag(sk, SOCK_ZAPPED);
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
return 0;
}
示例2: tipc_create
/**
* tipc_create - create a TIPC socket
* @sock: pre-allocated socket structure
* @protocol: protocol indicator (must be 0)
*
* This routine creates and attaches a 'struct sock' to the 'struct socket',
* then create and attaches a TIPC port to the 'struct sock' part.
*
* Returns 0 on success, errno otherwise
*/
static int tipc_create(struct socket *sock, int protocol)
{
struct tipc_sock *tsock;
struct tipc_port *port;
struct sock *sk;
u32 ref;
if (unlikely(protocol != 0))
return -EPROTONOSUPPORT;
ref = tipc_createport_raw(NULL, &dispatch, &wakeupdispatch, TIPC_LOW_IMPORTANCE);
if (unlikely(!ref))
return -ENOMEM;
sock->state = SS_UNCONNECTED;
switch (sock->type) {
case SOCK_STREAM:
sock->ops = &stream_ops;
break;
case SOCK_SEQPACKET:
sock->ops = &packet_ops;
break;
case SOCK_DGRAM:
tipc_set_portunreliable(ref, 1);
/* fall through */
case SOCK_RDM:
tipc_set_portunreturnable(ref, 1);
sock->ops = &msg_ops;
sock->state = SS_READY;
break;
default:
tipc_deleteport(ref);
return -EPROTOTYPE;
}
sk = sk_alloc(AF_TIPC, GFP_KERNEL, &tipc_proto);
if (!sk) {
tipc_deleteport(ref);
return -ENOMEM;
}
sock_init_data(sock, sk);
init_waitqueue_head(sk->sk_sleep);
sk->sk_rcvtimeo = 8 * HZ; /* default connect timeout = 8s */
tsock = tipc_sk(sk);
port = tipc_get_port(ref);
tsock->p = port;
port->usr_handle = tsock;
init_MUTEX(&tsock->sem);
dbg("sock_create: %x\n",tsock);
atomic_inc(&tipc_user_count);
return 0;
}
示例3: rawsock_create
static int rawsock_create(struct net *net, struct socket *sock,
const struct nfc_protocol *nfc_proto)
{
struct sock *sk;
nfc_dbg("sock=%p", sock);
if (sock->type != SOCK_SEQPACKET)
return -ESOCKTNOSUPPORT;
sock->ops = &rawsock_ops;
sk = sk_alloc(net, PF_NFC, GFP_KERNEL, nfc_proto->proto);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sk->sk_protocol = nfc_proto->id;
sk->sk_destruct = rawsock_destruct;
sock->state = SS_UNCONNECTED;
INIT_WORK(&nfc_rawsock(sk)->tx_work, rawsock_tx_work);
nfc_rawsock(sk)->tx_work_scheduled = false;
return 0;
}
示例4: bnep_sock_create
static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
BT_DBG("sock %p", sock);
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &bnep_proto, kern);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sock->ops = &bnep_sock_ops;
sock->state = SS_UNCONNECTED;
sock_reset_flag(sk, SOCK_ZAPPED);
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
bt_sock_link(&bnep_sk_list, sk);
return 0;
}
示例5: pn_socket_create
static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
{
struct sock *sk;
struct pn_sock *pn;
struct phonet_protocol *pnp;
int err;
#if !defined (CONFIG_SAMSUNG_PHONE_SVNET) && !defined (CONFIG_SAMSUNG_PHONE_SVNET_MODULE)
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
#endif
if (protocol == 0) {
/* Default protocol selection */
switch (sock->type) {
case SOCK_DGRAM:
protocol = PN_PROTO_PHONET;
break;
case SOCK_SEQPACKET:
protocol = PN_PROTO_PIPE;
break;
default:
return -EPROTONOSUPPORT;
}
}
pnp = phonet_proto_get(protocol);
if (pnp == NULL &&
request_module("net-pf-%d-proto-%d", PF_PHONET, protocol) == 0)
pnp = phonet_proto_get(protocol);
if (pnp == NULL)
return -EPROTONOSUPPORT;
if (sock->type != pnp->sock_type) {
err = -EPROTONOSUPPORT;
goto out;
}
sk = sk_alloc(net, PF_PHONET, GFP_KERNEL, pnp->prot);
if (sk == NULL) {
err = -ENOMEM;
goto out;
}
sock_init_data(sock, sk);
sock->state = SS_UNCONNECTED;
sock->ops = pnp->ops;
sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
sk->sk_protocol = protocol;
pn = pn_sk(sk);
pn->sobject = 0;
pn->resource = 0;
sk->sk_prot->init(sk);
err = 0;
out:
phonet_proto_put(pnp);
return err;
}
示例6: MksckCreate
static int
MksckCreate(struct net *net,
struct socket *sock,
int protocol,
int kern)
{
struct sock *sk;
uid_t currentUid = current_euid();
if (!(currentUid == 0 ||
currentUid == Mvpkm_vmwareUid)) {
pr_warn("MksckCreate: rejected from process %s " \
"tgid=%d, pid=%d euid:%d.\n",
current->comm,
task_tgid_vnr(current),
task_pid_vnr(current),
currentUid);
return -EPERM;
}
if (!sock)
return -EINVAL;
if (protocol)
return -EPROTONOSUPPORT;
switch (sock->type) {
case SOCK_DGRAM:
sock->ops = &mksckDgramOps;
break;
default:
return -ESOCKTNOSUPPORT;
}
sock->state = SS_UNCONNECTED;
sk = sk_alloc(net, mksckFamilyOps.family, GFP_KERNEL, &mksckProto);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sk->sk_type = SOCK_DGRAM;
sk->sk_destruct = MksckSkDestruct;
sk->sk_backlog_rcv = MksckBacklogRcv;
sk->sk_protinfo = NULL;
sock_reset_flag(sk, SOCK_DONE);
return 0;
}
示例7: ieee802154_create
/*
* Create a socket. Initialise the socket, blank the addresses
* set the state.
*/
static int ieee802154_create(struct net *net, struct socket *sock,
int protocol, int kern)
{
struct sock *sk;
int rc;
struct proto *proto;
const struct proto_ops *ops;
if (net != &init_net)
return -EAFNOSUPPORT;
switch (sock->type) {
case SOCK_RAW:
proto = &ieee802154_raw_prot;
ops = &ieee802154_raw_ops;
break;
case SOCK_DGRAM:
proto = &ieee802154_dgram_prot;
ops = &ieee802154_dgram_ops;
break;
default:
rc = -ESOCKTNOSUPPORT;
goto out;
}
rc = -ENOMEM;
sk = sk_alloc(net, PF_IEEE802154, GFP_KERNEL, proto);
if (!sk)
goto out;
rc = 0;
sock->ops = ops;
sock_init_data(sock, sk);
/* FIXME: sk->sk_destruct */
sk->sk_family = PF_IEEE802154;
/* Checksums on by default */
sock_set_flag(sk, SOCK_ZAPPED);
if (sk->sk_prot->hash)
sk->sk_prot->hash(sk);
if (sk->sk_prot->init) {
rc = sk->sk_prot->init(sk);
if (rc)
sk_common_release(sk);
}
out:
return rc;
}
示例8: rxrpc_create
/*
* create an RxRPC socket
*/
static int rxrpc_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct rxrpc_net *rxnet;
struct rxrpc_sock *rx;
struct sock *sk;
_enter("%p,%d", sock, protocol);
/* we support transport protocol UDP/UDP6 only */
if (protocol != PF_INET &&
IS_ENABLED(CONFIG_AF_RXRPC_IPV6) && protocol != PF_INET6)
return -EPROTONOSUPPORT;
if (sock->type != SOCK_DGRAM)
return -ESOCKTNOSUPPORT;
sock->ops = &rxrpc_rpc_ops;
sock->state = SS_UNCONNECTED;
sk = sk_alloc(net, PF_RXRPC, GFP_KERNEL, &rxrpc_proto, kern);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sock_set_flag(sk, SOCK_RCU_FREE);
sk->sk_state = RXRPC_UNBOUND;
sk->sk_write_space = rxrpc_write_space;
sk->sk_max_ack_backlog = 0;
sk->sk_destruct = rxrpc_sock_destructor;
rx = rxrpc_sk(sk);
rx->family = protocol;
rx->calls = RB_ROOT;
spin_lock_init(&rx->incoming_lock);
INIT_LIST_HEAD(&rx->sock_calls);
INIT_LIST_HEAD(&rx->to_be_accepted);
INIT_LIST_HEAD(&rx->recvmsg_q);
rwlock_init(&rx->recvmsg_lock);
rwlock_init(&rx->call_lock);
memset(&rx->srx, 0, sizeof(rx->srx));
rxnet = rxrpc_net(sock_net(&rx->sk));
timer_reduce(&rxnet->peer_keepalive_timer, jiffies + 1);
_leave(" = 0 [%p]", rx);
return 0;
}
示例9: sk_alloc
/**
* llc_sk_alloc - Allocates LLC sock
* @family: upper layer protocol family
* @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
*
* Allocates a LLC sock and initializes it. Returns the new LLC sock
* or %NULL if there's no memory available for one
*/
struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority, struct proto *prot)
{
struct sock *sk = sk_alloc(net, family, priority, prot);
if (!sk)
goto out;
llc_sk_init(sk);
sock_init_data(NULL, sk);
#ifdef LLC_REFCNT_DEBUG
atomic_inc(&llc_sock_nr);
// printk(KERN_DEBUG "LLC socket %p created in %s, now we have %d alive\n", sk,
;
#endif
out:
return sk;
}
示例10: raw_create
/*
* sys_socket -> sock_create -> __sock_create -> this
*/
static int raw_create(struct net *net, struct socket *sock, int protocol, int kern)
{
struct sock *sk;
int err;
/* init sock struct */
err = -ENOBUFS;
sk = sk_alloc(net, PF_RAW, GFP_KERNEL, &raw_proto);
if (sk == NULL)
goto out;
sock->ops = &raw_ops;
sock_init_data(sock, sk);
sk->sk_family = PF_RAW;
err = 0;
out:
return err;
}
示例11: sk_alloc
static struct sock *nr_alloc_sock(void)
{
nr_cb *nr;
struct sock *sk = sk_alloc(PF_NETROM, GFP_ATOMIC, 1, NULL);
if (!sk)
goto out;
nr = sk->sk_protinfo = kmalloc(sizeof(*nr), GFP_ATOMIC);
if (!nr)
goto frees;
memset(nr, 0x00, sizeof(*nr));
nr->sk = sk;
out:
return sk;
frees:
sk_free(sk);
sk = NULL;
goto out;
}
示例12: vcc_create
int vcc_create(struct socket *sock, int protocol, int family)
{
struct sock *sk;
struct atm_vcc *vcc;
sock->sk = NULL;
if (sock->type == SOCK_STREAM)
return -EINVAL;
sk = sk_alloc(family, GFP_KERNEL, 1, NULL);
if (!sk)
return -ENOMEM;
sock_init_data(sock, sk);
sk_set_owner(sk, THIS_MODULE);
sk->sk_state_change = vcc_def_wakeup;
sk->sk_write_space = vcc_write_space;
vcc = sk->sk_protinfo = kmalloc(sizeof(*vcc), GFP_KERNEL);
if (!vcc) {
sk_free(sk);
return -ENOMEM;
}
memset(vcc, 0, sizeof(*vcc));
vcc->sk = sk;
vcc->dev = NULL;
memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc));
memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc));
vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
atomic_set(&vcc->sk->sk_wmem_alloc, 0);
atomic_set(&vcc->sk->sk_rmem_alloc, 0);
vcc->push = NULL;
vcc->pop = NULL;
vcc->push_oam = NULL;
vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
vcc->atm_options = vcc->aal_options = 0;
sk->sk_destruct = vcc_sock_destruct;
sock->sk = sk;
return 0;
}
示例13: sizeof
static struct sock *rose_alloc_sock(void)
{
struct sock *sk;
rose_cb *rose;
if ((sk = sk_alloc(PF_ROSE, GFP_ATOMIC, 1)) == NULL)
return NULL;
if ((rose = kmalloc(sizeof(*rose), GFP_ATOMIC)) == NULL) {
sk_free(sk);
return NULL;
}
MOD_INC_USE_COUNT;
memset(rose, 0x00, sizeof(*rose));
sk->protinfo.rose = rose;
rose->sk = sk;
return sk;
}
示例14: sk_alloc
struct sock *alloc_atm_vcc_sk(int family)
{
struct sock *sk;
struct atm_vcc *vcc;
sk = sk_alloc(family, GFP_KERNEL, 1);
if (!sk) return NULL;
vcc = sk->protinfo.af_atm = kmalloc(sizeof(*vcc),GFP_KERNEL);
if (!vcc) {
sk_free(sk);
return NULL;
}
sock_init_data(NULL,sk);
sk->destruct = atm_free_sock;
memset(vcc,0,sizeof(*vcc));
vcc->sk = sk;
if (nodev_vccs) nodev_vccs->prev = vcc;
vcc->prev = NULL;
vcc->next = nodev_vccs;
nodev_vccs = vcc;
return sk;
}
示例15: sk_alloc
struct sock *sk_clone(struct sock *sk, const gfp_t priority)
{
struct sock *newsk = sk_alloc(sk->sk_family, priority, sk->sk_prot, 0);
if (newsk != NULL) {
struct sk_filter *filter;
memcpy(newsk, sk, sk->sk_prot->obj_size);
/* SANITY */
sk_node_init(&newsk->sk_node);
sock_lock_init(newsk);
bh_lock_sock(newsk);
atomic_set(&newsk->sk_rmem_alloc, 0);
atomic_set(&newsk->sk_wmem_alloc, 0);
atomic_set(&newsk->sk_omem_alloc, 0);
skb_queue_head_init(&newsk->sk_receive_queue);
skb_queue_head_init(&newsk->sk_write_queue);
rwlock_init(&newsk->sk_dst_lock);
rwlock_init(&newsk->sk_callback_lock);
newsk->sk_dst_cache = NULL;
newsk->sk_wmem_queued = 0;
newsk->sk_forward_alloc = 0;
newsk->sk_send_head = NULL;
newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK;
sock_reset_flag(newsk, SOCK_DONE);
skb_queue_head_init(&newsk->sk_error_queue);
filter = newsk->sk_filter;
if (filter != NULL)
sk_filter_charge(newsk, filter);
if (sk->sk_create_child)
sk->sk_create_child(sk, newsk);
if (unlikely(xfrm_sk_clone_policy(newsk))) {
/* It is still raw copy of parent, so invalidate
* destructor and make plain sk_free() */
newsk->sk_destruct = NULL;
sk_free(newsk);
newsk = NULL;
goto out;
}
newsk->sk_err = 0;
newsk->sk_priority = 0;
atomic_set(&newsk->sk_refcnt, 2);
/*
* Increment the counter in the same struct proto as the master
* sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
* is the same as sk->sk_prot->socks, as this field was copied
* with memcpy).
*
* This _changes_ the previous behaviour, where
* tcp_create_openreq_child always was incrementing the
* equivalent to tcp_prot->socks (inet_sock_nr), so this have
* to be taken into account in all callers. -acme
*/
sk_refcnt_debug_inc(newsk);
newsk->sk_socket = NULL;
newsk->sk_sleep = NULL;
if (newsk->sk_prot->sockets_allocated)
atomic_inc(newsk->sk_prot->sockets_allocated);
}
out:
return newsk;
}