Commit 3d970ece authored by David Howells's avatar David Howells Committed by Linus Torvalds

[PATCH] AFS filesystem (1/2)

This adds RxRPC support to Linux for use by the AFS filesystem
parent ce1fedaa
/* call.h: Rx call record
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_CALL_H
#define _LINUX_RXRPC_CALL_H
#include <rxrpc/types.h>
#include <rxrpc/rxrpc.h>
#include <rxrpc/packet.h>
#include <linux/timer.h>
#define RXRPC_CALL_ACK_WINDOW_SIZE 16
extern unsigned rxrpc_call_rcv_timeout; /* receive activity timeout (secs) */
extern unsigned rxrpc_call_acks_timeout; /* pending ACK (retransmit) timeout (secs) */
extern unsigned rxrpc_call_dfr_ack_timeout; /* deferred ACK timeout (secs) */
extern unsigned short rxrpc_call_max_resend; /* maximum consecutive resend count */
/* application call state
* - only state 0 and ffff are reserved, the state is set to 1 after an opid is received
*/
enum rxrpc_app_cstate {
RXRPC_CSTATE_COMPLETE = 0, /* operation complete */
RXRPC_CSTATE_ERROR, /* operation ICMP error or aborted */
RXRPC_CSTATE_SRVR_RCV_OPID, /* [SERVER] receiving operation ID */
RXRPC_CSTATE_SRVR_RCV_ARGS, /* [SERVER] receiving operation data */
RXRPC_CSTATE_SRVR_GOT_ARGS, /* [SERVER] completely received operation data */
RXRPC_CSTATE_SRVR_SND_REPLY, /* [SERVER] sending operation reply */
RXRPC_CSTATE_SRVR_RCV_FINAL_ACK, /* [SERVER] receiving final ACK */
RXRPC_CSTATE_CLNT_SND_ARGS, /* [CLIENT] sending operation args */
RXRPC_CSTATE_CLNT_RCV_REPLY, /* [CLIENT] receiving operation reply */
RXRPC_CSTATE_CLNT_GOT_REPLY, /* [CLIENT] completely received operation reply */
} __attribute__((packed));
extern const char *rxrpc_call_states[];
enum rxrpc_app_estate {
RXRPC_ESTATE_NO_ERROR = 0, /* no error */
RXRPC_ESTATE_LOCAL_ABORT, /* aborted locally by application layer */
RXRPC_ESTATE_PEER_ABORT, /* aborted remotely by peer */
RXRPC_ESTATE_LOCAL_ERROR, /* local ICMP network error */
RXRPC_ESTATE_REMOTE_ERROR, /* remote ICMP network error */
} __attribute__((packed));
extern const char *rxrpc_call_error_states[];
/*****************************************************************************/
/*
* Rx call record and application scratch buffer
* - the call record occupies the bottom of a complete page
* - the application scratch buffer occupies the rest
*/
struct rxrpc_call
{
atomic_t usage;
struct rxrpc_connection *conn; /* connection upon which active */
spinlock_t lock; /* access lock */
struct module *owner; /* owner module */
wait_queue_head_t waitq; /* wait queue for events to happen */
struct list_head link; /* general internal list link */
struct list_head call_link; /* master call list link */
u32 chan_ix; /* connection channel index (net order) */
u32 call_id; /* call ID on connection (net order) */
unsigned long cjif; /* jiffies at call creation */
unsigned long flags; /* control flags */
#define RXRPC_CALL_ACKS_TIMO 0x00000001 /* ACKS timeout reached */
#define RXRPC_CALL_ACKR_TIMO 0x00000002 /* ACKR timeout reached */
#define RXRPC_CALL_RCV_TIMO 0x00000004 /* RCV timeout reached */
#define RXRPC_CALL_RCV_PKT 0x00000008 /* received packet */
/* transmission */
rxrpc_seq_t snd_seq_count; /* outgoing packet sequence number counter */
struct rxrpc_message *snd_nextmsg; /* next message being constructed for sending */
struct rxrpc_message *snd_ping; /* last ping message sent */
unsigned short snd_resend_cnt; /* count of resends since last ACK */
/* transmission ACK tracking */
struct list_head acks_pendq; /* messages pending ACK (ordered by seq) */
unsigned acks_pend_cnt; /* number of un-ACK'd packets */
rxrpc_seq_t acks_dftv_seq; /* highest definitively ACK'd msg seq */
struct timer_list acks_timeout; /* timeout on expected ACK */
/* reception */
struct list_head rcv_receiveq; /* messages pending reception (ordered by seq) */
struct list_head rcv_krxiodq_lk; /* krxiod queue for new inbound packets */
struct timer_list rcv_timeout; /* call receive activity timeout */
/* reception ACK'ing */
rxrpc_seq_t ackr_win_bot; /* bottom of ACK window */
rxrpc_seq_t ackr_win_top; /* top of ACK window */
rxrpc_seq_t ackr_high_seq; /* highest seqno yet received */
rxrpc_seq_t ackr_prev_seq; /* previous seqno received */
unsigned ackr_pend_cnt; /* number of pending ACKs */
struct timer_list ackr_dfr_timo; /* timeout on deferred ACK */
char ackr_dfr_perm; /* request for deferred ACKs permitted */
rxrpc_seq_t ackr_dfr_seq; /* seqno for deferred ACK */
struct rxrpc_ackpacket ackr; /* pending normal ACK packet */
u8 ackr_array[RXRPC_CALL_ACK_WINDOW_SIZE]; /* ACK records */
/* presentation layer */
char app_last_rcv; /* T if received last packet from remote end */
enum rxrpc_app_cstate app_call_state; /* call state */
enum rxrpc_app_estate app_err_state; /* abort/error state */
struct list_head app_readyq; /* ordered ready received packet queue */
struct list_head app_unreadyq; /* ordered post-hole recv'd packet queue */
rxrpc_seq_t app_ready_seq; /* last seq number dropped into readyq */
size_t app_ready_qty; /* amount of data ready in readyq */
unsigned app_opcode; /* operation ID */
unsigned app_abort_code; /* abort code (when aborted) */
int app_errno; /* error number (when ICMP error received) */
/* statisics */
unsigned pkt_rcv_count; /* count of received packets on this call */
unsigned pkt_snd_count; /* count of sent packets on this call */
unsigned app_read_count; /* number of reads issued */
/* bits for the application to use */
rxrpc_call_attn_func_t app_attn_func; /* callback when attention required */
rxrpc_call_error_func_t app_error_func; /* callback when abort sent (cleanup and put) */
rxrpc_call_aemap_func_t app_aemap_func; /* callback to map abort code to/from errno */
void *app_user; /* application data */
struct list_head app_link; /* application list linkage */
struct list_head app_attn_link; /* application attention list linkage */
size_t app_mark; /* trigger callback when app_ready_qty>=app_mark */
char app_async_read; /* T if in async-read mode */
u8 *app_read_buf; /* application async read buffer (app_mark size) */
u8 *app_scr_alloc; /* application scratch allocation pointer */
void *app_scr_ptr; /* application pointer into scratch buffer */
#define RXRPC_APP_MARK_EOF 0xFFFFFFFFU /* mark at end of input */
/* application scratch buffer */
u8 app_scratch[0] __attribute__((aligned(sizeof(long))));
};
#define RXRPC_CALL_SCRATCH_SIZE (PAGE_SIZE - sizeof(struct rxrpc_call))
#define rxrpc_call_reset_scratch(CALL) \
do { (CALL)->app_scr_alloc = (CALL)->app_scratch; } while(0)
#define rxrpc_call_alloc_scratch(CALL,SIZE) \
({ \
void *ptr; \
ptr = (CALL)->app_scr_alloc; \
(CALL)->app_scr_alloc += (SIZE); \
if ((SIZE)>RXRPC_CALL_SCRATCH_SIZE || \
(size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
printk("rxrpc_call_alloc_scratch(%p,%u)\n",(CALL),(SIZE)); \
BUG(); \
} \
ptr; \
})
#define rxrpc_call_alloc_scratch_s(CALL,TYPE) \
({ \
size_t size = sizeof(TYPE); \
TYPE *ptr; \
ptr = (TYPE*)(CALL)->app_scr_alloc; \
(CALL)->app_scr_alloc += size; \
if (size>RXRPC_CALL_SCRATCH_SIZE || \
(size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
printk("rxrpc_call_alloc_scratch(%p,%u)\n",(CALL),size); \
BUG(); \
} \
ptr; \
})
#define rxrpc_call_is_ack_pending(CALL) ((CALL)->ackr.reason != 0)
extern int rxrpc_create_call(struct rxrpc_connection *conn,
rxrpc_call_attn_func_t attn,
rxrpc_call_error_func_t error,
rxrpc_call_aemap_func_t aemap,
struct rxrpc_call **_call);
extern int rxrpc_incoming_call(struct rxrpc_connection *conn,
struct rxrpc_message *msg,
struct rxrpc_call **_call);
static inline void rxrpc_get_call(struct rxrpc_call *call)
{
if (atomic_read(&call->usage)<=0)
BUG();
atomic_inc(&call->usage);
/*printk("rxrpc_get_call(%p{u=%d})\n",(C),atomic_read(&(C)->usage));*/
}
extern void rxrpc_put_call(struct rxrpc_call *call);
extern void rxrpc_call_do_stuff(struct rxrpc_call *call);
extern int rxrpc_call_abort(struct rxrpc_call *call, int error);
#define RXRPC_CALL_READ_BLOCK 0x0001 /* block if not enough data and not yet EOF */
#define RXRPC_CALL_READ_ALL 0x0002 /* error if insufficient data received */
extern int rxrpc_call_read_data(struct rxrpc_call *call, void *buffer, size_t size, int flags);
extern int rxrpc_call_write_data(struct rxrpc_call *call,
size_t sioc,
struct iovec siov[],
u8 rxhdr_flags,
int alloc_flags,
int dup_data,
size_t *size_sent);
extern int rxrpc_call_flush(struct rxrpc_call *call);
extern void rxrpc_call_handle_error(struct rxrpc_call *conn, int local, int errno);
#endif /* _LINUX_RXRPC_CALL_H */
/* connection.h: Rx connection record
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_CONNECTION_H
#define _LINUX_RXRPC_CONNECTION_H
#include <rxrpc/types.h>
#include <rxrpc/krxtimod.h>
struct sk_buff;
/*****************************************************************************/
/*
* Rx connection
* - connections are matched by (rmt_port,rmt_addr,service_id,conn_id,clientflag)
* - connections only retain a refcount on the peer when they are active
* - connections with refcount==0 are inactive and reside in the peer's graveyard
*/
struct rxrpc_connection
{
atomic_t usage;
struct rxrpc_transport *trans; /* transport endpoint */
struct rxrpc_peer *peer; /* peer from/to which connected */
struct rxrpc_service *service; /* responsible service (inbound conns) */
struct rxrpc_timer timeout; /* decaching timer */
struct list_head link; /* link in peer's list */
struct list_head proc_link; /* link in proc list */
struct list_head err_link; /* link in ICMP error processing list */
struct sockaddr_in addr; /* remote address */
struct rxrpc_call *channels[4]; /* channels (active calls) */
wait_queue_head_t chanwait; /* wait for channel to become available */
spinlock_t lock; /* access lock */
struct timeval atime; /* last access time */
size_t mtu_size; /* MTU size for outbound messages */
unsigned call_counter; /* call ID counter */
rxrpc_serial_t serial_counter; /* packet serial number counter */
/* the following should all be in net order */
u32 in_epoch; /* peer's epoch */
u32 out_epoch; /* my epoch */
u32 conn_id; /* connection ID, appropriately shifted */
u16 service_id; /* service ID */
u8 security_ix; /* security ID */
u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */
u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
};
extern int rxrpc_create_connection(struct rxrpc_transport *trans,
u16 port,
u32 addr,
unsigned short service_id,
void *security,
struct rxrpc_connection **_conn);
extern int rxrpc_connection_lookup(struct rxrpc_peer *peer,
struct rxrpc_message *msg,
struct rxrpc_connection **_conn);
static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
{
if (atomic_read(&conn->usage)<0)
BUG();
atomic_inc(&conn->usage);
//printk("rxrpc_get_conn(%p{u=%d})\n",conn,atomic_read(&conn->usage));
}
extern void rxrpc_put_connection(struct rxrpc_connection *conn);
extern int rxrpc_conn_receive_call_packet(struct rxrpc_connection *conn,
struct rxrpc_call *call,
struct rxrpc_message *msg);
extern void rxrpc_conn_handle_error(struct rxrpc_connection *conn, int local, int errno);
#endif /* _LINUX_RXRPC_CONNECTION_H */
/* krxiod.h: Rx RPC I/O kernel thread interface
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_KRXIOD_H
#define _LINUX_RXRPC_KRXIOD_H
#include <rxrpc/types.h>
extern int rxrpc_krxiod_init(void);
extern void rxrpc_krxiod_kill(void);
extern void rxrpc_krxiod_queue_transport(struct rxrpc_transport *trans);
extern void rxrpc_krxiod_dequeue_transport(struct rxrpc_transport *trans);
extern void rxrpc_krxiod_queue_peer(struct rxrpc_peer *peer);
extern void rxrpc_krxiod_dequeue_peer(struct rxrpc_peer *peer);
extern void rxrpc_krxiod_clear_peers(struct rxrpc_transport *trans);
extern void rxrpc_krxiod_queue_call(struct rxrpc_call *call);
extern void rxrpc_krxiod_dequeue_call(struct rxrpc_call *call);
#endif /* _LINUX_RXRPC_KRXIOD_H */
/* krxsecd.h: Rx RPC security kernel thread interface
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_KRXSECD_H
#define _LINUX_RXRPC_KRXSECD_H
#include <rxrpc/types.h>
extern int rxrpc_krxsecd_init(void);
extern void rxrpc_krxsecd_kill(void);
extern void rxrpc_krxsecd_clear_transport(struct rxrpc_transport *trans);
extern void rxrpc_krxsecd_queue_incoming_call(struct rxrpc_message *msg);
#endif /* _LINUX_RXRPC_KRXSECD_H */
/* krxtimod.h: RxRPC timeout daemon
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_KRXTIMOD_H
#define _LINUX_RXRPC_KRXTIMOD_H
#include <rxrpc/types.h>
struct rxrpc_timer_ops {
/* called when the front of the timer queue has timed out */
void (*timed_out)(struct rxrpc_timer *timer);
};
/*****************************************************************************/
/*
* RXRPC timer/timeout record
*/
struct rxrpc_timer
{
struct list_head link; /* link in timer queue */
unsigned long timo_jif; /* timeout time */
const struct rxrpc_timer_ops *ops; /* timeout expiry function */
};
static inline void rxrpc_timer_init(rxrpc_timer_t *timer, const struct rxrpc_timer_ops *ops)
{
INIT_LIST_HEAD(&timer->link);
timer->ops = ops;
}
extern int rxrpc_krxtimod_start(void);
extern void rxrpc_krxtimod_kill(void);
extern void rxrpc_krxtimod_add_timer(rxrpc_timer_t *timer, unsigned long timeout);
extern int rxrpc_krxtimod_del_timer(rxrpc_timer_t *timer);
#endif /* _LINUX_RXRPC_KRXTIMOD_H */
/* message.h: Rx message caching
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _H_3AD3363A_3A9C_11D6_83D8_0002B3163499
#define _H_3AD3363A_3A9C_11D6_83D8_0002B3163499
#include <rxrpc/packet.h>
/*****************************************************************************/
/*
* Rx message record
*/
struct rxrpc_message
{
atomic_t usage;
struct list_head link; /* list link */
struct timeval stamp; /* time received or last sent */
rxrpc_seq_t seq; /* message sequence number */
int state; /* the state the message is currently in */
#define RXRPC_MSG_PREPARED 0
#define RXRPC_MSG_SENT 1
#define RXRPC_MSG_ACKED 2 /* provisionally ACK'd */
#define RXRPC_MSG_DONE 3 /* definitively ACK'd (msg->seq<ack.firstPacket) */
#define RXRPC_MSG_RECEIVED 4
#define RXRPC_MSG_ERROR -1
char rttdone; /* used for RTT */
struct rxrpc_transport *trans; /* transport received through */
struct rxrpc_connection *conn; /* connection received over */
struct sk_buff *pkt; /* received packet */
off_t offset; /* offset into pkt of next byte of data */
struct rxrpc_header hdr; /* message header */
int dcount; /* data part count */
size_t dsize; /* data size */
#define RXRPC_MSG_MAX_IOCS 8
struct iovec data[RXRPC_MSG_MAX_IOCS]; /* message data */
unsigned long dfree; /* bit mask indicating kfree(data[x]) if T */
};
#define rxrpc_get_message(M) do { atomic_inc(&(M)->usage); } while(0)
extern void __rxrpc_put_message(struct rxrpc_message *msg);
static inline void rxrpc_put_message(struct rxrpc_message *msg)
{
if (atomic_read(&msg->usage)<=0)
BUG();
if (atomic_dec_and_test(&msg->usage))
__rxrpc_put_message(msg);
}
extern int rxrpc_conn_newmsg(struct rxrpc_connection *conn,
struct rxrpc_call *call,
u8 type,
int count,
struct iovec diov[],
int alloc_flags,
struct rxrpc_message **_msg);
extern int rxrpc_conn_sendmsg(struct rxrpc_connection *conn, struct rxrpc_message *msg);
#endif /* _H_3AD3363A_3A9C_11D6_83D8_0002B3163499 */
/* packet.h: Rx packet layout and definitions
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_PACKET_H
#define _LINUX_RXRPC_PACKET_H
#include <rxrpc/types.h>
#define RXRPC_IPUDP_SIZE 28
extern size_t RXRPC_MAX_PACKET_SIZE;
#define RXRPC_MAX_PACKET_DATA_SIZE (RXRPC_MAX_PACKET_SIZE - sizeof(struct rxrpc_header))
#define RXRPC_LOCAL_PACKET_SIZE RXRPC_MAX_PACKET_SIZE
#define RXRPC_REMOTE_PACKET_SIZE (576 - RXRPC_IPUDP_SIZE)
/*****************************************************************************/
/*
* on-the-wire Rx packet header
* - all multibyte fields should be in network byte order
*/
struct rxrpc_header
{
u32 epoch; /* client boot timestamp */
u32 cid; /* connection and channel ID */
#define RXRPC_MAXCALLS 4 /* max active calls per conn */
#define RXRPC_CHANNELMASK (RXRPC_MAXCALLS-1) /* mask for channel ID */
#define RXRPC_CIDMASK (~RXRPC_CHANNELMASK) /* mask for connection ID */
#define RXRPC_CIDSHIFT 2 /* shift for connection ID */
u32 callNumber; /* call ID (0 for connection-level packets) */
#define RXRPC_PROCESS_MAXCALLS (1<<2) /* maximum number of active calls per conn (power of 2) */
u32 seq; /* sequence number of pkt in call stream */
u32 serial; /* serial number of pkt sent to network */
u8 type; /* packet type */
#define RXRPC_PACKET_TYPE_DATA 1 /* data */
#define RXRPC_PACKET_TYPE_ACK 2 /* ACK */
#define RXRPC_PACKET_TYPE_BUSY 3 /* call reject */
#define RXRPC_PACKET_TYPE_ABORT 4 /* call/connection abort */
#define RXRPC_PACKET_TYPE_ACKALL 5 /* ACK all outstanding packets on call */
#define RXRPC_PACKET_TYPE_CHALLENGE 6 /* connection security challenge (SRVR->CLNT) */
#define RXRPC_PACKET_TYPE_RESPONSE 7 /* connection secutity response (CLNT->SRVR) */
#define RXRPC_PACKET_TYPE_DEBUG 8 /* debug info request */
#define RXRPC_N_PACKET_TYPES 9 /* number of packet types (incl type 0) */
u8 flags; /* packet flags */
#define RXRPC_CLIENT_INITIATED 0x01 /* signifies a packet generated by a client */
#define RXRPC_REQUEST_ACK 0x02 /* request an unconditional ACK of this packet */
#define RXRPC_LAST_PACKET 0x04 /* the last packet from this side for this call */
#define RXRPC_MORE_PACKETS 0x08 /* more packets to come */
#define RXRPC_JUMBO_PACKET 0x20 /* [DATA] this is a jumbo packet */
#define RXRPC_SLOW_START_OK 0x20 /* [ACK] slow start supported */
u8 userStatus; /* app-layer defined status */
u8 securityIndex; /* security protocol ID */
u16 _rsvd; /* reserved (used by kerberos security as cksum) */
u16 serviceId; /* service ID */
} __attribute__((packed));
#define __rxrpc_header_off(X) offsetof(struct rxrpc_header,X)
extern const char *rxrpc_pkts[];
/*****************************************************************************/
/*
* jumbo packet secondary header
* - can be mapped to read header by:
* - new_serial = serial + 1
* - new_seq = seq + 1
* - new_flags = j_flags
* - new__rsvd = j__rsvd
* - duplicating all other fields
*/
struct rxrpc_jumbo_header
{
u8 flags; /* packet flags (as per rxrpc_header) */
u8 pad;
u16 _rsvd; /* reserved (used by kerberos security as cksum) */
};
#define RXRPC_JUMBO_DATALEN 1412 /* non-terminal jumbo packet data length */
/*****************************************************************************/
/*
* on-the-wire Rx ACK packet data payload
* - all multibyte fields should be in network byte order
*/
struct rxrpc_ackpacket
{
u16 bufferSpace; /* number of packet buffers available */
u16 maxSkew; /* diff between serno being ACK'd and highest serial no received */
u32 firstPacket; /* sequence no of first ACK'd packet in attached list */
u32 previousPacket; /* sequence no of previous packet received */
u32 serial; /* serial no of packet that prompted this ACK */
u8 reason; /* reason for ACK */
#define RXRPC_ACK_REQUESTED 1 /* ACK was requested on packet */
#define RXRPC_ACK_DUPLICATE 2 /* duplicate packet received */
#define RXRPC_ACK_OUT_OF_SEQUENCE 3 /* out of sequence packet received */
#define RXRPC_ACK_EXCEEDS_WINDOW 4 /* packet received beyond end of ACK window */
#define RXRPC_ACK_NOSPACE 5 /* packet discarded due to lack of buffer space */
#define RXRPC_ACK_PING 6 /* keep alive ACK */
#define RXRPC_ACK_PING_RESPONSE 7 /* response to RXRPC_ACK_PING */
#define RXRPC_ACK_DELAY 8 /* nothing happened since received packet */
#define RXRPC_ACK_IDLE 9 /* ACK due to fully received ACK window */
u8 nAcks; /* number of ACKs */
#define RXRPC_MAXACKS 255
u8 acks[0]; /* list of ACK/NAKs */
#define RXRPC_ACK_TYPE_NACK 0
#define RXRPC_ACK_TYPE_ACK 1
} __attribute__((packed));
extern const char *rxrpc_acks[];
#endif /* _LINUX_RXRPC_PACKET_H */
/* peer.h: Rx RPC per-transport peer record
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_PEER_H
#define _LINUX_RXRPC_PEER_H
#include <linux/wait.h>
#include <rxrpc/types.h>
#include <rxrpc/krxtimod.h>
struct rxrpc_peer_ops
{
/* peer record being added */
int (*adding)(struct rxrpc_peer *peer);
/* peer record being discarded from graveyard */
void (*discarding)(struct rxrpc_peer *peer);
/* change of epoch detected on connection */
void (*change_of_epoch)(struct rxrpc_connection *conn);
};
/*****************************************************************************/
/*
* Rx RPC per-transport peer record
* - peers only retain a refcount on the transport when they are active
* - peers with refcount==0 are inactive and reside in the transport's graveyard
*/
struct rxrpc_peer
{
atomic_t usage;
struct rxrpc_peer_ops *ops; /* operations on this peer */
struct rxrpc_transport *trans; /* owner transport */
struct rxrpc_timer timeout; /* timeout for grave destruction */
struct list_head link; /* link in transport's peer list */
struct list_head proc_link; /* link in /proc list */
rwlock_t conn_lock; /* lock for connections */
struct list_head conn_active; /* active connections to/from this peer */
struct list_head conn_graveyard; /* graveyard for inactive connections */
spinlock_t conn_gylock; /* lock for conn_graveyard */
wait_queue_head_t conn_gy_waitq; /* wait queue hit when graveyard is empty */
atomic_t conn_count; /* number of attached connections */
struct in_addr addr; /* remote address */
size_t if_mtu; /* interface MTU for this peer */
spinlock_t lock; /* access lock */
void *user; /* application layer data */
/* calculated RTT cache */
#define RXRPC_RTT_CACHE_SIZE 32
suseconds_t rtt; /* current RTT estimate (in uS) */
unsigned short rtt_point; /* next entry at which to insert */
unsigned short rtt_usage; /* amount of cache actually used */
suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
};
extern int rxrpc_peer_lookup(struct rxrpc_transport *trans,
u32 addr,
struct rxrpc_peer **_peer);
static inline void rxrpc_get_peer(struct rxrpc_peer *peer)
{
if (atomic_read(&peer->usage)<0)
BUG();
atomic_inc(&peer->usage);
//printk("rxrpc_get_peer(%p{u=%d})\n",peer,atomic_read(&peer->usage));
}
extern void rxrpc_put_peer(struct rxrpc_peer *peer);
#endif /* _LINUX_RXRPC_PEER_H */
/* rx.h: Rx RPC interface
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_RXRPC_H
#define _LINUX_RXRPC_RXRPC_H
#ifdef __KERNEL__
extern u32 rxrpc_epoch;
extern int rxrpc_ktrace;
extern int rxrpc_kdebug;
extern int rxrpc_kproto;
extern int rxrpc_knet;
extern int rxrpc_sysctl_init(void);
extern void rxrpc_sysctl_cleanup(void);
#endif /* __KERNEL__ */
#endif /* _LINUX_RXRPC_RXRPC_H */
/* transport.h: Rx transport management
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_TRANSPORT_H
#define _LINUX_RXRPC_TRANSPORT_H
#include <rxrpc/types.h>
#include <rxrpc/krxiod.h>
#include <rxrpc/rxrpc.h>
#include <linux/skbuff.h>
#include <linux/rwsem.h>
typedef int (*rxrpc_newcall_fnx_t)(struct rxrpc_call *call);
extern wait_queue_head_t rxrpc_krxiod_wq;
/*****************************************************************************/
/*
* Rx operation specification
* - tables of these must be sorted by op ID so that they can be binary-chop searched
*/
struct rxrpc_operation
{
unsigned id; /* operation ID */
size_t asize; /* minimum size of argument block */
const char *name; /* name of operation */
void *user; /* initial user data */
};
/*****************************************************************************/
/*
* Rx transport service record
*/
struct rxrpc_service
{
struct list_head link; /* link in services list on transport */
struct module *owner; /* owner module */
rxrpc_newcall_fnx_t new_call; /* new call handler function */
const char *name; /* name of service */
unsigned short service_id; /* Rx service ID */
rxrpc_call_attn_func_t attn_func; /* call requires attention callback */
rxrpc_call_error_func_t error_func; /* call error callback */
rxrpc_call_aemap_func_t aemap_func; /* abort -> errno mapping callback */
const struct rxrpc_operation *ops_begin; /* beginning of operations table */
const struct rxrpc_operation *ops_end; /* end of operations table */
};
/*****************************************************************************/
/*
* Rx transport endpoint record
*/
struct rxrpc_transport
{
atomic_t usage;
struct socket *socket; /* my UDP socket */
struct list_head services; /* services listening on this socket */
struct list_head link; /* link in transport list */
struct list_head proc_link; /* link in transport proc list */
struct list_head krxiodq_link; /* krxiod attention queue link */
spinlock_t lock; /* access lock */
struct list_head peer_active; /* active peers connected to over this socket */
struct list_head peer_graveyard; /* inactive peer list */
spinlock_t peer_gylock; /* peer graveyard lock */
wait_queue_head_t peer_gy_waitq; /* wait queue hit when peer graveyard is empty */
rwlock_t peer_lock; /* peer list access lock */
atomic_t peer_count; /* number of peers */
struct rxrpc_peer_ops *peer_ops; /* default peer operations */
unsigned short port; /* port upon which listening */
volatile char error_rcvd; /* T if received ICMP error outstanding */
};
extern struct list_head rxrpc_transports;
extern int rxrpc_create_transport(unsigned short port,
struct rxrpc_transport **_trans);
static inline void rxrpc_get_transport(struct rxrpc_transport *trans)
{
if (atomic_read(&trans->usage)<=0)
BUG();
atomic_inc(&trans->usage);
//printk("rxrpc_get_transport(%p{u=%d})\n",trans,atomic_read(&trans->usage));
}
extern void rxrpc_put_transport(struct rxrpc_transport *trans);
extern int rxrpc_add_service(struct rxrpc_transport *trans,
struct rxrpc_service *srv);
extern void rxrpc_del_service(struct rxrpc_transport *trans,
struct rxrpc_service *srv);
#if 0
extern int rxrpc_trans_add_connection(struct rxrpc_transport *trans,
struct rxrpc_connection *conn);
#endif
extern void rxrpc_trans_receive_packet(struct rxrpc_transport *trans);
extern int rxrpc_trans_immediate_abort(struct rxrpc_transport *trans,
struct rxrpc_message *msg,
int error);
extern void rxrpc_clear_transport(struct rxrpc_transport *trans);
#endif /* _LINUX_RXRPC_TRANSPORT_H */
/* types.h: Rx types
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _LINUX_RXRPC_TYPES_H
#define _LINUX_RXRPC_TYPES_H
#include <linux/types.h>
#include <linux/list.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/spinlock.h>
#include <asm/atomic.h>
typedef unsigned rxrpc_seq_t; /* Rx message sequence number */
typedef unsigned rxrpc_serial_t; /* Rx message serial number */
struct rxrpc_call;
struct rxrpc_connection;
struct rxrpc_header;
struct rxrpc_message;
struct rxrpc_operation;
struct rxrpc_peer;
struct rxrpc_service;
typedef struct rxrpc_timer rxrpc_timer_t;
struct rxrpc_transport;
typedef void (*rxrpc_call_attn_func_t)(struct rxrpc_call *call);
typedef void (*rxrpc_call_error_func_t)(struct rxrpc_call *call);
typedef void (*rxrpc_call_aemap_func_t)(struct rxrpc_call *call);
#endif /* _LINUX_RXRPC_TYPES_H */
...@@ -29,6 +29,7 @@ obj-$(CONFIG_AX25) += ax25/ ...@@ -29,6 +29,7 @@ obj-$(CONFIG_AX25) += ax25/
obj-$(CONFIG_IRDA) += irda/ obj-$(CONFIG_IRDA) += irda/
obj-$(CONFIG_BT) += bluetooth/ obj-$(CONFIG_BT) += bluetooth/
obj-$(CONFIG_SUNRPC) += sunrpc/ obj-$(CONFIG_SUNRPC) += sunrpc/
obj-$(CONFIG_RXRPC) += rxrpc/
obj-$(CONFIG_ATM) += atm/ obj-$(CONFIG_ATM) += atm/
obj-$(CONFIG_DECNET) += decnet/ obj-$(CONFIG_DECNET) += decnet/
obj-$(CONFIG_ECONET) += econet/ obj-$(CONFIG_ECONET) += econet/
......
#
# Makefile for Linux kernel Rx RPC
#
export-objs := rxrpc_syms.o
rxrpc-objs := \
call.o \
connection.o \
krxiod.o \
krxsecd.o \
krxtimod.o \
main.o \
peer.o \
rxrpc_syms.o \
transport.o
#ifeq ($(CONFIG_PROC_FS),y)
rxrpc-objs += proc.o
#endif
#ifeq ($(CONFIG_SYSCTL),y)
rxrpc-objs += sysctl.o
#endif
obj-m := rxrpc.o
# superfluous for 2.5, but needed for 2.4..
ifeq "$(VERSION).$(PATCHLEVEL)" "2.4"
rxrpc.o: $(rxrpc-objs)
$(LD) -r -o $@ $(rxrpc-objs)
endif
include $(TOPDIR)/Rules.make
This diff is collapsed.
This diff is collapsed.
/* internal.h: internal Rx RPC stuff
*
* Copyright (c) 2002 David Howells (dhowells@redhat.com).
*/
#ifndef RXRPC_INTERNAL_H
#define RXRPC_INTERNAL_H
#include <linux/compiler.h>
#include <linux/kernel.h>
/*
* debug accounting
*/
#if 1
#define __RXACCT_DECL(X) X
#define __RXACCT(X) do { X; } while(0)
#else
#define __RXACCT_DECL(X)
#define __RXACCT(X) do { } while(0)
#endif
__RXACCT_DECL(extern atomic_t rxrpc_transport_count);
__RXACCT_DECL(extern atomic_t rxrpc_peer_count);
__RXACCT_DECL(extern atomic_t rxrpc_connection_count);
__RXACCT_DECL(extern atomic_t rxrpc_call_count);
__RXACCT_DECL(extern atomic_t rxrpc_message_count);
/*
* debug tracing
*/
#define kenter(FMT,...) printk("==> %s("FMT")\n",__FUNCTION__,##__VA_ARGS__)
#define kleave(FMT,...) printk("<== %s()"FMT"\n",__FUNCTION__,##__VA_ARGS__)
#define kdebug(FMT,...) printk(" "FMT"\n",##__VA_ARGS__)
#define kproto(FMT,...) printk("### "FMT"\n",##__VA_ARGS__)
#define knet(FMT,...) printk(" "FMT"\n",##__VA_ARGS__)
#if 0
#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
#define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
#define _net(FMT,...) knet(FMT,##__VA_ARGS__)
#else
#define _enter(FMT,...) do { if (rxrpc_ktrace) kenter(FMT,##__VA_ARGS__); } while(0)
#define _leave(FMT,...) do { if (rxrpc_ktrace) kleave(FMT,##__VA_ARGS__); } while(0)
#define _debug(FMT,...) do { if (rxrpc_kdebug) kdebug(FMT,##__VA_ARGS__); } while(0)
#define _proto(FMT,...) do { if (rxrpc_kproto) kproto(FMT,##__VA_ARGS__); } while(0)
#define _net(FMT,...) do { if (rxrpc_knet) knet (FMT,##__VA_ARGS__); } while(0)
#endif
static inline void rxrpc_discard_my_signals(void)
{
while (signal_pending(current)) {
siginfo_t sinfo;
spin_lock_irq(&current->sig->siglock);
dequeue_signal(&current->blocked,&sinfo);
spin_unlock_irq(&current->sig->siglock);
}
}
/*
* call.c
*/
extern struct list_head rxrpc_calls;
extern struct rw_semaphore rxrpc_calls_sem;
/*
* connection.c
*/
extern struct list_head rxrpc_conns;
extern struct rw_semaphore rxrpc_conns_sem;
extern void rxrpc_conn_do_timeout(struct rxrpc_connection *conn);
extern void rxrpc_conn_clearall(struct rxrpc_peer *peer);
/*
* peer.c
*/
extern struct list_head rxrpc_peers;
extern struct rw_semaphore rxrpc_peers_sem;
extern void rxrpc_peer_calculate_rtt(struct rxrpc_peer *peer,
struct rxrpc_message *msg,
struct rxrpc_message *resp);
extern void rxrpc_peer_clearall(struct rxrpc_transport *trans);
extern void rxrpc_peer_do_timeout(struct rxrpc_peer *peer);
/*
* proc.c
*/
#ifdef CONFIG_PROC_FS
extern int rxrpc_proc_init(void);
extern void rxrpc_proc_cleanup(void);
#endif
/*
* transport.c
*/
extern struct list_head rxrpc_proc_transports;
extern struct rw_semaphore rxrpc_proc_transports_sem;
#endif /* RXRPC_INTERNAL_H */
/* krxiod.c: Rx I/O daemon
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/version.h>
#include <linux/sched.h>
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/init.h>
#include <rxrpc/krxiod.h>
#include <rxrpc/transport.h>
#include <rxrpc/peer.h>
#include <rxrpc/call.h>
#include "internal.h"
static DECLARE_WAIT_QUEUE_HEAD(rxrpc_krxiod_sleepq);
static DECLARE_COMPLETION(rxrpc_krxiod_dead);
static atomic_t rxrpc_krxiod_qcount = ATOMIC_INIT(0);
static LIST_HEAD(rxrpc_krxiod_transportq);
static spinlock_t rxrpc_krxiod_transportq_lock = SPIN_LOCK_UNLOCKED;
static LIST_HEAD(rxrpc_krxiod_callq);
static spinlock_t rxrpc_krxiod_callq_lock = SPIN_LOCK_UNLOCKED;
static volatile int rxrpc_krxiod_die;
/*****************************************************************************/
/*
* Rx I/O daemon
*/
static int rxrpc_krxiod(void *arg)
{
DECLARE_WAITQUEUE(krxiod,current);
printk("Started krxiod %d\n",current->pid);
strcpy(current->comm,"krxiod");
daemonize();
/* only certain signals are of interest */
spin_lock_irq(&current->sig->siglock);
siginitsetinv(&current->blocked,0);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,3)
recalc_sigpending();
#else
recalc_sigpending(current);
#endif
spin_unlock_irq(&current->sig->siglock);
/* loop around waiting for work to do */
do {
/* wait for work or to be told to exit */
_debug("### Begin Wait");
if (!atomic_read(&rxrpc_krxiod_qcount)) {
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&rxrpc_krxiod_sleepq,&krxiod);
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
if (atomic_read(&rxrpc_krxiod_qcount) ||
rxrpc_krxiod_die ||
signal_pending(current))
break;
schedule();
}
remove_wait_queue(&rxrpc_krxiod_sleepq,&krxiod);
set_current_state(TASK_RUNNING);
}
_debug("### End Wait");
/* do work if been given some to do */
_debug("### Begin Work");
/* see if there's a transport in need of attention */
if (!list_empty(&rxrpc_krxiod_transportq)) {
struct rxrpc_transport *trans = NULL;
spin_lock_irq(&rxrpc_krxiod_transportq_lock);
if (!list_empty(&rxrpc_krxiod_transportq)) {
trans = list_entry(rxrpc_krxiod_transportq.next,
struct rxrpc_transport,krxiodq_link);
list_del_init(&trans->krxiodq_link);
atomic_dec(&rxrpc_krxiod_qcount);
/* make sure it hasn't gone away and doesn't go away */
if (atomic_read(&trans->usage)>0)
rxrpc_get_transport(trans);
else
trans = NULL;
}
spin_unlock_irq(&rxrpc_krxiod_transportq_lock);
if (trans) {
rxrpc_trans_receive_packet(trans);
rxrpc_put_transport(trans);
}
}
/* see if there's a call in need of attention */
if (!list_empty(&rxrpc_krxiod_callq)) {
struct rxrpc_call *call = NULL;
spin_lock_irq(&rxrpc_krxiod_callq_lock);
if (!list_empty(&rxrpc_krxiod_callq)) {
call = list_entry(rxrpc_krxiod_callq.next,
struct rxrpc_call,rcv_krxiodq_lk);
list_del_init(&call->rcv_krxiodq_lk);
atomic_dec(&rxrpc_krxiod_qcount);
/* make sure it hasn't gone away and doesn't go away */
if (atomic_read(&call->usage)>0) {
_debug("@@@ KRXIOD Begin Attend Call %p",call);
rxrpc_get_call(call);
}
else {
call = NULL;
}
}
spin_unlock_irq(&rxrpc_krxiod_callq_lock);
if (call) {
rxrpc_call_do_stuff(call);
rxrpc_put_call(call);
_debug("@@@ KRXIOD End Attend Call %p",call);
}
}
_debug("### End Work");
/* discard pending signals */
rxrpc_discard_my_signals();
} while (!rxrpc_krxiod_die);
/* and that's all */
complete_and_exit(&rxrpc_krxiod_dead,0);
} /* end rxrpc_krxiod() */
/*****************************************************************************/
/*
* start up a krxiod daemon
*/
int __init rxrpc_krxiod_init(void)
{
return kernel_thread(rxrpc_krxiod,NULL,0);
} /* end rxrpc_krxiod_init() */
/*****************************************************************************/
/*
* kill the krxiod daemon and wait for it to complete
*/
void rxrpc_krxiod_kill(void)
{
rxrpc_krxiod_die = 1;
wake_up_all(&rxrpc_krxiod_sleepq);
wait_for_completion(&rxrpc_krxiod_dead);
} /* end rxrpc_krxiod_kill() */
/*****************************************************************************/
/*
* queue a transport for attention by krxiod
*/
void rxrpc_krxiod_queue_transport(struct rxrpc_transport *trans)
{
unsigned long flags;
_enter("");
if (list_empty(&trans->krxiodq_link)) {
spin_lock_irqsave(&rxrpc_krxiod_transportq_lock,flags);
if (list_empty(&trans->krxiodq_link)) {
if (atomic_read(&trans->usage)>0) {
list_add_tail(&trans->krxiodq_link,&rxrpc_krxiod_transportq);
atomic_inc(&rxrpc_krxiod_qcount);
}
}
spin_unlock_irqrestore(&rxrpc_krxiod_transportq_lock,flags);
wake_up_all(&rxrpc_krxiod_sleepq);
}
_leave("");
} /* end rxrpc_krxiod_queue_transport() */
/*****************************************************************************/
/*
* dequeue a transport from krxiod's attention queue
*/
void rxrpc_krxiod_dequeue_transport(struct rxrpc_transport *trans)
{
unsigned long flags;
_enter("");
spin_lock_irqsave(&rxrpc_krxiod_transportq_lock,flags);
if (!list_empty(&trans->krxiodq_link)) {
list_del_init(&trans->krxiodq_link);
atomic_dec(&rxrpc_krxiod_qcount);
}
spin_unlock_irqrestore(&rxrpc_krxiod_transportq_lock,flags);
_leave("");
} /* end rxrpc_krxiod_dequeue_transport() */
/*****************************************************************************/
/*
* queue a call for attention by krxiod
*/
void rxrpc_krxiod_queue_call(struct rxrpc_call *call)
{
unsigned long flags;
if (list_empty(&call->rcv_krxiodq_lk)) {
spin_lock_irqsave(&rxrpc_krxiod_callq_lock,flags);
if (atomic_read(&call->usage)>0) {
list_add_tail(&call->rcv_krxiodq_lk,&rxrpc_krxiod_callq);
atomic_inc(&rxrpc_krxiod_qcount);
}
spin_unlock_irqrestore(&rxrpc_krxiod_callq_lock,flags);
}
wake_up_all(&rxrpc_krxiod_sleepq);
} /* end rxrpc_krxiod_queue_call() */
/*****************************************************************************/
/*
* dequeue a call from krxiod's attention queue
*/
void rxrpc_krxiod_dequeue_call(struct rxrpc_call *call)
{
unsigned long flags;
spin_lock_irqsave(&rxrpc_krxiod_callq_lock,flags);
if (!list_empty(&call->rcv_krxiodq_lk)) {
list_del_init(&call->rcv_krxiodq_lk);
atomic_dec(&rxrpc_krxiod_qcount);
}
spin_unlock_irqrestore(&rxrpc_krxiod_callq_lock,flags);
} /* end rxrpc_krxiod_dequeue_call() */
/* krxsecd.c: Rx security daemon
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* This daemon deals with:
* - consulting the application as to whether inbound peers and calls should be authorised
* - generating security challenges for inbound connections
* - responding to security challenges on outbound connections
*/
#include <linux/version.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/init.h>
#include <rxrpc/krxsecd.h>
#include <rxrpc/transport.h>
#include <rxrpc/connection.h>
#include <rxrpc/message.h>
#include <rxrpc/peer.h>
#include <rxrpc/call.h>
#include <linux/udp.h>
#include <linux/ip.h>
#include <net/sock.h>
#include "internal.h"
static DECLARE_WAIT_QUEUE_HEAD(rxrpc_krxsecd_sleepq);
static DECLARE_COMPLETION(rxrpc_krxsecd_dead);
static volatile int rxrpc_krxsecd_die;
static atomic_t rxrpc_krxsecd_qcount;
/* queue of unprocessed inbound messages with seqno #1 and RXRPC_CLIENT_INITIATED flag set */
static LIST_HEAD(rxrpc_krxsecd_initmsgq);
static spinlock_t rxrpc_krxsecd_initmsgq_lock = SPIN_LOCK_UNLOCKED;
static void rxrpc_krxsecd_process_incoming_call(struct rxrpc_message *msg);
/*****************************************************************************/
/*
* Rx security daemon
*/
static int rxrpc_krxsecd(void *arg)
{
DECLARE_WAITQUEUE(krxsecd,current);
int die;
printk("Started krxsecd %d\n",current->pid);
strcpy(current->comm,"krxsecd");
daemonize();
/* only certain signals are of interest */
spin_lock_irq(&current->sig->siglock);
siginitsetinv(&current->blocked,0);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,3)
recalc_sigpending();
#else
recalc_sigpending(current);
#endif
spin_unlock_irq(&current->sig->siglock);
/* loop around waiting for work to do */
do {
/* wait for work or to be told to exit */
_debug("### Begin Wait");
if (!atomic_read(&rxrpc_krxsecd_qcount)) {
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&rxrpc_krxsecd_sleepq,&krxsecd);
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
if (atomic_read(&rxrpc_krxsecd_qcount) ||
rxrpc_krxsecd_die ||
signal_pending(current))
break;
schedule();
}
remove_wait_queue(&rxrpc_krxsecd_sleepq,&krxsecd);
set_current_state(TASK_RUNNING);
}
die = rxrpc_krxsecd_die;
_debug("### End Wait");
/* see if there're incoming calls in need of authenticating */
_debug("### Begin Inbound Calls");
if (!list_empty(&rxrpc_krxsecd_initmsgq)) {
struct rxrpc_message *msg = NULL;
spin_lock(&rxrpc_krxsecd_initmsgq_lock);
if (!list_empty(&rxrpc_krxsecd_initmsgq)) {
msg = list_entry(rxrpc_krxsecd_initmsgq.next,
struct rxrpc_message,link);
list_del_init(&msg->link);
atomic_dec(&rxrpc_krxsecd_qcount);
}
spin_unlock(&rxrpc_krxsecd_initmsgq_lock);
if (msg) {
rxrpc_krxsecd_process_incoming_call(msg);
rxrpc_put_message(msg);
}
}
_debug("### End Inbound Calls");
/* discard pending signals */
rxrpc_discard_my_signals();
} while (!die);
/* and that's all */
complete_and_exit(&rxrpc_krxsecd_dead,0);
} /* end rxrpc_krxsecd() */
/*****************************************************************************/
/*
* start up a krxsecd daemon
*/
int __init rxrpc_krxsecd_init(void)
{
return kernel_thread(rxrpc_krxsecd,NULL,0);
} /* end rxrpc_krxsecd_init() */
/*****************************************************************************/
/*
* kill the krxsecd daemon and wait for it to complete
*/
void rxrpc_krxsecd_kill(void)
{
rxrpc_krxsecd_die = 1;
wake_up_all(&rxrpc_krxsecd_sleepq);
wait_for_completion(&rxrpc_krxsecd_dead);
} /* end rxrpc_krxsecd_kill() */
/*****************************************************************************/
/*
* clear all pending incoming calls for the specified transport
*/
void rxrpc_krxsecd_clear_transport(struct rxrpc_transport *trans)
{
LIST_HEAD(tmp);
struct rxrpc_message *msg;
struct list_head *_p, *_n;
_enter("%p",trans);
/* move all the messages for this transport onto a temp list */
spin_lock(&rxrpc_krxsecd_initmsgq_lock);
list_for_each_safe(_p,_n,&rxrpc_krxsecd_initmsgq) {
msg = list_entry(_p,struct rxrpc_message,link);
if (msg->trans==trans) {
list_del(&msg->link);
list_add_tail(&msg->link,&tmp);
atomic_dec(&rxrpc_krxsecd_qcount);
}
}
spin_unlock(&rxrpc_krxsecd_initmsgq_lock);
/* zap all messages on the temp list */
while (!list_empty(&tmp)) {
msg = list_entry(tmp.next,struct rxrpc_message,link);
list_del_init(&msg->link);
rxrpc_put_message(msg);
}
_leave("");
} /* end rxrpc_krxsecd_clear_transport() */
/*****************************************************************************/
/*
* queue a message on the incoming calls list
*/
void rxrpc_krxsecd_queue_incoming_call(struct rxrpc_message *msg)
{
_enter("%p",msg);
/* queue for processing by krxsecd */
spin_lock(&rxrpc_krxsecd_initmsgq_lock);
if (!rxrpc_krxsecd_die) {
rxrpc_get_message(msg);
list_add_tail(&msg->link,&rxrpc_krxsecd_initmsgq);
atomic_inc(&rxrpc_krxsecd_qcount);
}
spin_unlock(&rxrpc_krxsecd_initmsgq_lock);
wake_up(&rxrpc_krxsecd_sleepq);
_leave("");
} /* end rxrpc_krxsecd_queue_incoming_call() */
/*****************************************************************************/
/*
* process the initial message of an incoming call
*/
void rxrpc_krxsecd_process_incoming_call(struct rxrpc_message *msg)
{
struct rxrpc_transport *trans = msg->trans;
struct rxrpc_service *srv;
struct rxrpc_call *call;
struct list_head *_p;
unsigned short sid;
int ret;
_enter("%p{tr=%p}",msg,trans);
ret = rxrpc_incoming_call(msg->conn,msg,&call);
if (ret<0)
goto out;
/* find the matching service on the transport */
sid = ntohs(msg->hdr.serviceId);
srv = NULL;
spin_lock(&trans->lock);
list_for_each(_p,&trans->services) {
srv = list_entry(_p,struct rxrpc_service,link);
if (srv->service_id==sid && try_inc_mod_count(srv->owner)) {
/* found a match (made sure it won't vanish) */
_debug("found service '%s'",srv->name);
call->owner = srv->owner;
break;
}
}
spin_unlock(&trans->lock);
/* report the new connection
* - the func must inc the call's usage count to keep it
*/
ret = -ENOENT;
if (_p!=&trans->services) {
/* attempt to accept the call */
call->conn->service = srv;
call->app_attn_func = srv->attn_func;
call->app_error_func = srv->error_func;
call->app_aemap_func = srv->aemap_func;
ret = srv->new_call(call);
/* send an abort if an error occurred */
if (ret<0) {
rxrpc_call_abort(call,ret);
}
else {
/* formally receive and ACK the new packet */
ret = rxrpc_conn_receive_call_packet(call->conn,call,msg);
}
}
rxrpc_put_call(call);
out:
if (ret<0)
rxrpc_trans_immediate_abort(trans,msg,ret);
_leave(" (%d)",ret);
} /* end rxrpc_krxsecd_process_incoming_call() */
/* krxtimod.c: RXRPC timeout daemon
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/completion.h>
#include <rxrpc/rxrpc.h>
#include <rxrpc/krxtimod.h>
#include <asm/errno.h>
#include "internal.h"
static DECLARE_COMPLETION(krxtimod_alive);
static DECLARE_COMPLETION(krxtimod_dead);
static DECLARE_WAIT_QUEUE_HEAD(krxtimod_sleepq);
static int krxtimod_die;
static LIST_HEAD(krxtimod_list);
static spinlock_t krxtimod_lock = SPIN_LOCK_UNLOCKED;
static int krxtimod(void *arg);
/*****************************************************************************/
/*
* start the timeout daemon
*/
int rxrpc_krxtimod_start(void)
{
int ret;
ret = kernel_thread(krxtimod,NULL,0);
if (ret<0)
return ret;
wait_for_completion(&krxtimod_alive);
return ret;
} /* end rxrpc_krxtimod_start() */
/*****************************************************************************/
/*
* stop the timeout daemon
*/
void rxrpc_krxtimod_kill(void)
{
/* get rid of my daemon */
krxtimod_die = 1;
wake_up(&krxtimod_sleepq);
wait_for_completion(&krxtimod_dead);
} /* end rxrpc_krxtimod_kill() */
/*****************************************************************************/
/*
* timeout processing daemon
*/
static int krxtimod(void *arg)
{
DECLARE_WAITQUEUE(myself,current);
rxrpc_timer_t *timer;
printk("Started krxtimod %d\n",current->pid);
strcpy(current->comm,"krxtimod");
daemonize();
complete(&krxtimod_alive);
/* only certain signals are of interest */
spin_lock_irq(&current->sig->siglock);
siginitsetinv(&current->blocked,0);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,3)
recalc_sigpending();
#else
recalc_sigpending(current);
#endif
spin_unlock_irq(&current->sig->siglock);
/* loop around looking for things to attend to */
loop:
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&krxtimod_sleepq,&myself);
for (;;) {
unsigned long jif;
signed long timeout;
/* deal with the server being asked to die */
if (krxtimod_die) {
remove_wait_queue(&krxtimod_sleepq,&myself);
_leave("");
complete_and_exit(&krxtimod_dead,0);
}
/* discard pending signals */
rxrpc_discard_my_signals();
/* work out the time to elapse before the next event */
spin_lock(&krxtimod_lock);
if (list_empty(&krxtimod_list)) {
timeout = MAX_SCHEDULE_TIMEOUT;
}
else {
timer = list_entry(krxtimod_list.next,rxrpc_timer_t,link);
timeout = timer->timo_jif;
jif = jiffies;
if (time_before_eq(timeout,jif))
goto immediate;
else {
timeout = (long)timeout - (long)jiffies;
}
}
spin_unlock(&krxtimod_lock);
schedule_timeout(timeout);
set_current_state(TASK_INTERRUPTIBLE);
}
/* the thing on the front of the queue needs processing
* - we come here with the lock held and timer pointing to the expired entry
*/
immediate:
remove_wait_queue(&krxtimod_sleepq,&myself);
set_current_state(TASK_RUNNING);
_debug("@@@ Begin Timeout of %p",timer);
/* dequeue the timer */
list_del_init(&timer->link);
spin_unlock(&krxtimod_lock);
/* call the timeout function */
timer->ops->timed_out(timer);
_debug("@@@ End Timeout");
goto loop;
} /* end krxtimod() */
/*****************************************************************************/
/*
* (re-)queue a timer
*/
void rxrpc_krxtimod_add_timer(rxrpc_timer_t *timer, unsigned long timeout)
{
struct list_head *_p;
rxrpc_timer_t *ptimer;
_enter("%p,%lu",timer,timeout);
spin_lock(&krxtimod_lock);
list_del(&timer->link);
/* the timer was deferred or reset - put it back in the queue at the right place */
timer->timo_jif = jiffies + timeout;
list_for_each(_p,&krxtimod_list) {
ptimer = list_entry(_p,rxrpc_timer_t,link);
if (time_before(timer->timo_jif,ptimer->timo_jif))
break;
}
list_add_tail(&timer->link,_p); /* insert before stopping point */
spin_unlock(&krxtimod_lock);
wake_up(&krxtimod_sleepq);
_leave("");
} /* end rxrpc_krxtimod_queue_vlocation() */
/*****************************************************************************/
/*
* dequeue a timer
* - returns 0 if the timer was deleted or -ENOENT if it wasn't queued
*/
int rxrpc_krxtimod_del_timer(rxrpc_timer_t *timer)
{
int ret = 0;
_enter("%p",timer);
spin_lock(&krxtimod_lock);
if (list_empty(&timer->link))
ret = -ENOENT;
else
list_del_init(&timer->link);
spin_unlock(&krxtimod_lock);
wake_up(&krxtimod_sleepq);
_leave(" = %d",ret);
return ret;
} /* end rxrpc_krxtimod_del_timer() */
/* main.c: Rx RPC interface
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <rxrpc/rxrpc.h>
#include <rxrpc/krxiod.h>
#include <rxrpc/krxsecd.h>
#include <rxrpc/krxtimod.h>
#include <rxrpc/transport.h>
#include <rxrpc/connection.h>
#include <rxrpc/call.h>
#include <rxrpc/message.h>
#include "internal.h"
static int rxrpc_initialise(void);
static void rxrpc_cleanup(void);
module_init(rxrpc_initialise);
module_exit(rxrpc_cleanup);
MODULE_DESCRIPTION("Rx RPC implementation");
MODULE_AUTHOR("Red Hat, Inc.");
MODULE_LICENSE("GPL");
u32 rxrpc_epoch;
/*****************************************************************************/
/*
* initialise the Rx module
*/
static int rxrpc_initialise(void)
{
int ret;
/* my epoch value */
rxrpc_epoch = htonl(xtime.tv_sec);
/* register the /proc interface */
#ifdef CONFIG_PROC_FS
ret = rxrpc_proc_init();
if (ret<0)
return ret;
#endif
/* register the sysctl files */
#ifdef CONFIG_SYSCTL
ret = rxrpc_sysctl_init();
if (ret<0)
goto error_proc;
#endif
/* start the krxtimod daemon */
ret = rxrpc_krxtimod_start();
if (ret<0)
goto error_sysctl;
/* start the krxiod daemon */
ret = rxrpc_krxiod_init();
if (ret<0)
goto error_krxtimod;
/* start the krxsecd daemon */
ret = rxrpc_krxsecd_init();
if (ret<0)
goto error_krxiod;
kdebug("\n\n");
return 0;
error_krxiod:
rxrpc_krxiod_kill();
error_krxtimod:
rxrpc_krxtimod_kill();
error_sysctl:
#ifdef CONFIG_SYSCTL
rxrpc_sysctl_cleanup();
#endif
error_proc:
#ifdef CONFIG_PROC_FS
rxrpc_proc_cleanup();
#endif
return ret;
} /* end rxrpc_initialise() */
/*****************************************************************************/
/*
* clean up the Rx module
*/
static void rxrpc_cleanup(void)
{
kenter("");
__RXACCT(printk("Outstanding Messages : %d\n",atomic_read(&rxrpc_message_count)));
__RXACCT(printk("Outstanding Calls : %d\n",atomic_read(&rxrpc_call_count)));
__RXACCT(printk("Outstanding Connections: %d\n",atomic_read(&rxrpc_connection_count)));
__RXACCT(printk("Outstanding Peers : %d\n",atomic_read(&rxrpc_peer_count)));
__RXACCT(printk("Outstanding Transports : %d\n",atomic_read(&rxrpc_transport_count)));
rxrpc_krxsecd_kill();
rxrpc_krxiod_kill();
rxrpc_krxtimod_kill();
#ifdef CONFIG_SYSCTL
rxrpc_sysctl_cleanup();
#endif
#ifdef CONFIG_PROC_FS
rxrpc_proc_cleanup();
#endif
__RXACCT(printk("Outstanding Messages : %d\n",atomic_read(&rxrpc_message_count)));
__RXACCT(printk("Outstanding Calls : %d\n",atomic_read(&rxrpc_call_count)));
__RXACCT(printk("Outstanding Connections: %d\n",atomic_read(&rxrpc_connection_count)));
__RXACCT(printk("Outstanding Peers : %d\n",atomic_read(&rxrpc_peer_count)));
__RXACCT(printk("Outstanding Transports : %d\n",atomic_read(&rxrpc_transport_count)));
kleave();
} /* end rxrpc_cleanup() */
This diff is collapsed.
This diff is collapsed.
/* rxrpc_syms.c: exported Rx RPC layer interface symbols
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <rxrpc/transport.h>
#include <rxrpc/connection.h>
#include <rxrpc/call.h>
#include <rxrpc/krxiod.h>
/* call.c */
EXPORT_SYMBOL(rxrpc_call_rcv_timeout);
EXPORT_SYMBOL(rxrpc_call_acks_timeout);
EXPORT_SYMBOL(rxrpc_call_dfr_ack_timeout);
EXPORT_SYMBOL(rxrpc_call_max_resend);
EXPORT_SYMBOL(rxrpc_call_states);
EXPORT_SYMBOL(rxrpc_call_error_states);
EXPORT_SYMBOL(rxrpc_create_call);
EXPORT_SYMBOL(rxrpc_incoming_call);
EXPORT_SYMBOL(rxrpc_put_call);
EXPORT_SYMBOL(rxrpc_call_abort);
EXPORT_SYMBOL(rxrpc_call_read_data);
EXPORT_SYMBOL(rxrpc_call_write_data);
EXPORT_SYMBOL(rxrpc_call_flush);
/* connection.c */
EXPORT_SYMBOL(rxrpc_create_connection);
EXPORT_SYMBOL(rxrpc_put_connection);
/* sysctl.c */
EXPORT_SYMBOL(rxrpc_ktrace);
EXPORT_SYMBOL(rxrpc_kdebug);
EXPORT_SYMBOL(rxrpc_kproto);
EXPORT_SYMBOL(rxrpc_knet);
/* transport.c */
EXPORT_SYMBOL(rxrpc_create_transport);
EXPORT_SYMBOL(rxrpc_clear_transport);
EXPORT_SYMBOL(rxrpc_put_transport);
EXPORT_SYMBOL(rxrpc_add_service);
EXPORT_SYMBOL(rxrpc_del_service);
/* sysctl.c: Rx RPC control
*
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/sysctl.h>
#include <linux/config.h>
#include <rxrpc/types.h>
#include <rxrpc/rxrpc.h>
#include <asm/errno.h>
#include "internal.h"
int rxrpc_ktrace;
int rxrpc_kdebug;
int rxrpc_kproto;
int rxrpc_knet;
#ifdef CONFIG_SYSCTL
static struct ctl_table_header *rxrpc_sysctl = NULL;
static ctl_table rxrpc_sysctl_table[] = {
{ 1, "kdebug", &rxrpc_kdebug, sizeof(int), 0644, NULL, &proc_dointvec },
{ 2, "ktrace", &rxrpc_ktrace, sizeof(int), 0644, NULL, &proc_dointvec },
{ 3, "kproto", &rxrpc_kproto, sizeof(int), 0644, NULL, &proc_dointvec },
{ 4, "knet", &rxrpc_knet, sizeof(int), 0644, NULL, &proc_dointvec },
{ 0 }
};
static ctl_table rxrpc_dir_sysctl_table[] = {
{ 1, "rxrpc", NULL, 0, 0555, rxrpc_sysctl_table },
{ 0 }
};
#endif /* CONFIG_SYSCTL */
/*****************************************************************************/
/*
* initialise the sysctl stuff for Rx RPC
*/
int rxrpc_sysctl_init(void)
{
#ifdef CONFIG_SYSCTL
rxrpc_sysctl = register_sysctl_table(rxrpc_dir_sysctl_table,0);
if (!rxrpc_sysctl)
return -ENOMEM;
#endif /* CONFIG_SYSCTL */
return 0;
} /* end rxrpc_sysctl_init() */
/*****************************************************************************/
/*
* clean up the sysctl stuff for Rx RPC
*/
void rxrpc_sysctl_cleanup(void)
{
#ifdef CONFIG_SYSCTL
if (rxrpc_sysctl) {
unregister_sysctl_table(rxrpc_sysctl);
rxrpc_sysctl = NULL;
}
#endif /* CONFIG_SYSCTL */
} /* end rxrpc_sysctl_cleanup() */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment