Пример #1
0
/**
 * rxrpc_kernel_begin_call - Allow a kernel service to begin a call
 * @sock: The socket on which to make the call
 * @srx: The address of the peer to contact
 * @key: The security context to use (defaults to socket setting)
 * @user_call_ID: The ID to use
 * @tx_total_len: Total length of data to transmit during the call (or -1)
 * @gfp: The allocation constraints
 * @notify_rx: Where to send notifications instead of socket queue
 * @upgrade: Request service upgrade for call
 * @intr: The call is interruptible
 * @debug_id: The debug ID for tracing to be assigned to the call
 *
 * Allow a kernel service to begin a call on the nominated socket.  This just
 * sets up all the internal tracking structures and allocates connection and
 * call IDs as appropriate.  The call to be used is returned.
 *
 * The default socket destination address and security may be overridden by
 * supplying @srx and @key.
 */
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
					   struct sockaddr_rxrpc *srx,
					   struct key *key,
					   unsigned long user_call_ID,
					   s64 tx_total_len,
					   gfp_t gfp,
					   rxrpc_notify_rx_t notify_rx,
					   bool upgrade,
					   bool intr,
					   unsigned int debug_id)
{
	struct rxrpc_conn_parameters cp;
	struct rxrpc_call_params p;
	struct rxrpc_call *call;
	struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
	int ret;

	_enter(",,%x,%lx", key_serial(key), user_call_ID);

	ret = rxrpc_validate_address(rx, srx, sizeof(*srx));
	if (ret < 0)
		return ERR_PTR(ret);

	lock_sock(&rx->sk);

	if (!key)
		key = rx->key;
	if (key && !key->payload.data[0])
		key = NULL; /* a no-security key */

	memset(&p, 0, sizeof(p));
	p.user_call_ID = user_call_ID;
	p.tx_total_len = tx_total_len;
	p.intr = intr;

	memset(&cp, 0, sizeof(cp));
	cp.local		= rx->local;
	cp.key			= key;
	cp.security_level	= rx->min_sec_level;
	cp.exclusive		= false;
	cp.upgrade		= upgrade;
	cp.service_id		= srx->srx_service;
	call = rxrpc_new_client_call(rx, &cp, srx, &p, gfp, debug_id);
	/* The socket has been unlocked. */
	if (!IS_ERR(call)) {
		call->notify_rx = notify_rx;
		mutex_unlock(&call->user_mutex);
	}

	rxrpc_put_peer(cp.peer);
	_leave(" = %p", call);
	return call;
}
Пример #2
0
/*
 * handle an error received on the local endpoint
 */
void rxrpc_UDP_error_report(struct sock *sk)
{
    struct sock_exterr_skb *serr;
    struct rxrpc_transport *trans;
    struct rxrpc_local *local = sk->sk_user_data;
    struct rxrpc_peer *peer;
    struct sk_buff *skb;
    __be32 addr;
    __be16 port;

    _enter("%p{%d}", sk, local->debug_id);

    skb = skb_dequeue(&sk->sk_error_queue);
    if (!skb) {
        _leave("UDP socket errqueue empty");
        return;
    }

    rxrpc_new_skb(skb);

    serr = SKB_EXT_ERR(skb);
    addr = *(__be32 *)(skb_network_header(skb) + serr->addr_offset);
    port = serr->port;

    _net("Rx UDP Error from "NIPQUAD_FMT":%hu",
         NIPQUAD(addr), ntohs(port));
    _debug("Msg l:%d d:%d", skb->len, skb->data_len);

    peer = rxrpc_find_peer(local, addr, port);
    if (IS_ERR(peer)) {
        rxrpc_free_skb(skb);
        _leave(" [no peer]");
        return;
    }

    trans = rxrpc_find_transport(local, peer);
    if (!trans) {
        rxrpc_put_peer(peer);
        rxrpc_free_skb(skb);
        _leave(" [no trans]");
        return;
    }

    if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP &&
        serr->ee.ee_type == ICMP_DEST_UNREACH &&
        serr->ee.ee_code == ICMP_FRAG_NEEDED
        ) {
        u32 mtu = serr->ee.ee_info;

        _net("Rx Received ICMP Fragmentation Needed (%d)", mtu);

        /* wind down the local interface MTU */
        if (mtu > 0 && peer->if_mtu == 65535 && mtu < peer->if_mtu) {
            peer->if_mtu = mtu;
            _net("I/F MTU %u", mtu);
        }

        /* ip_rt_frag_needed() may have eaten the info */
        if (mtu == 0)
            mtu = ntohs(icmp_hdr(skb)->un.frag.mtu);

        if (mtu == 0) {
            /* they didn't give us a size, estimate one */
            if (mtu > 1500) {
                mtu >>= 1;
                if (mtu < 1500)
                    mtu = 1500;
            } else {
Пример #3
0
/*
 * accept an incoming call that needs peer, transport and/or connection setting
 * up
 */
static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
				      struct rxrpc_sock *rx,
				      struct sk_buff *skb,
				      struct sockaddr_rxrpc *srx)
{
	struct rxrpc_connection *conn;
	struct rxrpc_transport *trans;
	struct rxrpc_skb_priv *sp, *nsp;
	struct rxrpc_peer *peer;
	struct rxrpc_call *call;
	struct sk_buff *notification;
	int ret;

	_enter("");

	sp = rxrpc_skb(skb);

	/* get a notification message to send to the server app */
	notification = alloc_skb(0, GFP_NOFS);
	rxrpc_new_skb(notification);
	notification->mark = RXRPC_SKB_MARK_NEW_CALL;

	peer = rxrpc_get_peer(srx, GFP_NOIO);
	if (IS_ERR(peer)) {
		_debug("no peer");
		ret = -EBUSY;
		goto error;
	}

	trans = rxrpc_get_transport(local, peer, GFP_NOIO);
	rxrpc_put_peer(peer);
	if (!trans) {
		_debug("no trans");
		ret = -EBUSY;
		goto error;
	}

	conn = rxrpc_incoming_connection(trans, &sp->hdr, GFP_NOIO);
	rxrpc_put_transport(trans);
	if (IS_ERR(conn)) {
		_debug("no conn");
		ret = PTR_ERR(conn);
		goto error;
	}

	call = rxrpc_incoming_call(rx, conn, &sp->hdr, GFP_NOIO);
	rxrpc_put_connection(conn);
	if (IS_ERR(call)) {
		_debug("no call");
		ret = PTR_ERR(call);
		goto error;
	}

	/* attach the call to the socket */
	read_lock_bh(&local->services_lock);
	if (rx->sk.sk_state == RXRPC_CLOSE)
		goto invalid_service;

	write_lock(&rx->call_lock);
	if (!test_and_set_bit(RXRPC_CALL_INIT_ACCEPT, &call->flags)) {
		rxrpc_get_call(call);

		spin_lock(&call->conn->state_lock);
		if (sp->hdr.securityIndex > 0 &&
		    call->conn->state == RXRPC_CONN_SERVER_UNSECURED) {
			_debug("await conn sec");
			list_add_tail(&call->accept_link, &rx->secureq);
			call->conn->state = RXRPC_CONN_SERVER_CHALLENGING;
			atomic_inc(&call->conn->usage);
			set_bit(RXRPC_CONN_CHALLENGE, &call->conn->events);
			rxrpc_queue_conn(call->conn);
		} else {
			_debug("conn ready");
			call->state = RXRPC_CALL_SERVER_ACCEPTING;
			list_add_tail(&call->accept_link, &rx->acceptq);
			rxrpc_get_call(call);
			nsp = rxrpc_skb(notification);
			nsp->call = call;

			ASSERTCMP(atomic_read(&call->usage), >=, 3);

			_debug("notify");
			spin_lock(&call->lock);
			ret = rxrpc_queue_rcv_skb(call, notification, true,
						  false);
			spin_unlock(&call->lock);
			notification = NULL;
			if (ret < 0)
				BUG();
		}
		spin_unlock(&call->conn->state_lock);

		_debug("queued");
	}