⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocol.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 3 页
字号:
	} else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) {		retval = SCTP_SCOPE_LINK;	} else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) {		retval = SCTP_SCOPE_PRIVATE;	} else {		retval = SCTP_SCOPE_GLOBAL;	}	return retval;}/* Returns a valid dst cache entry for the given source and destination ip * addresses. If an association is passed, trys to get a dst entry with a * source address that matches an address in the bind address list. */struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,				  union sctp_addr *daddr,				  union sctp_addr *saddr){	struct rtable *rt;	struct flowi fl;	struct sctp_bind_addr *bp;	rwlock_t *addr_lock;	struct sctp_sockaddr_entry *laddr;	struct list_head *pos;	struct dst_entry *dst = NULL;	union sctp_addr dst_saddr;	memset(&fl, 0x0, sizeof(struct flowi));	fl.fl4_dst  = daddr->v4.sin_addr.s_addr;	fl.proto = IPPROTO_SCTP;	if (asoc) {		fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk);		fl.oif = asoc->base.sk->sk_bound_dev_if;	}	if (saddr)		fl.fl4_src = saddr->v4.sin_addr.s_addr;	SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ",			  __FUNCTION__, NIPQUAD(fl.fl4_dst),			  NIPQUAD(fl.fl4_src));	if (!ip_route_output_key(&rt, &fl)) {		dst = &rt->u.dst;	}	/* If there is no association or if a source address is passed, no	 * more validation is required.	 */	if (!asoc || saddr)		goto out;	bp = &asoc->base.bind_addr;	addr_lock = &asoc->base.addr_lock;	if (dst) {		/* Walk through the bind address list and look for a bind		 * address that matches the source address of the returned dst.		 */		sctp_read_lock(addr_lock);		list_for_each(pos, &bp->address_list) {			laddr = list_entry(pos, struct sctp_sockaddr_entry,					   list);			sctp_v4_dst_saddr(&dst_saddr, dst, bp->port);			if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a))				goto out_unlock;		}		sctp_read_unlock(addr_lock);		/* None of the bound addresses match the source address of the		 * dst. So release it.		 */		dst_release(dst);		dst = NULL;	}	/* Walk through the bind address list and try to get a dst that	 * matches a bind address as the source address.	 */	sctp_read_lock(addr_lock);	list_for_each(pos, &bp->address_list) {		laddr = list_entry(pos, struct sctp_sockaddr_entry, list);		if (AF_INET == laddr->a.sa.sa_family) {			fl.fl4_src = laddr->a.v4.sin_addr.s_addr;			if (!ip_route_output_key(&rt, &fl)) {				dst = &rt->u.dst;				goto out_unlock;			}		}	}out_unlock:	sctp_read_unlock(addr_lock);out:	if (dst)		SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n",			  	  NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src));	else		SCTP_DEBUG_PRINTK("NO ROUTE\n");	return dst;}/* For v4, the source address is cached in the route entry(dst). So no need * to cache it separately and hence this is an empty routine. */void sctp_v4_get_saddr(struct sctp_association *asoc,		       struct dst_entry *dst,		       union sctp_addr *daddr,		       union sctp_addr *saddr){	struct rtable *rt = (struct rtable *)dst;	if (rt) {		saddr->v4.sin_family = AF_INET;		saddr->v4.sin_port = asoc->base.bind_addr.port;  		saddr->v4.sin_addr.s_addr = rt->rt_src; 	}}/* What interface did this skb arrive on? */static int sctp_v4_skb_iif(const struct sk_buff *skb){     	return ((struct rtable *)skb->dst)->rt_iif;}/* Was this packet marked by Explicit Congestion Notification? */static int sctp_v4_is_ce(const struct sk_buff *skb){	return INET_ECN_is_ce(skb->nh.iph->tos);}/* Create and initialize a new sk for the socket returned by accept(). */struct sock *sctp_v4_create_accept_sk(struct sock *sk,				      struct sctp_association *asoc){	struct sock *newsk;	struct inet_opt *inet = inet_sk(sk);	struct inet_opt *newinet;	newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot->slab_obj_size,			 sk->sk_prot->slab);	if (!newsk)		goto out;	sock_init_data(NULL, newsk);	sk_set_owner(newsk, THIS_MODULE);	newsk->sk_type = SOCK_STREAM;	newsk->sk_prot = sk->sk_prot;	newsk->sk_no_check = sk->sk_no_check;	newsk->sk_reuse = sk->sk_reuse;	newsk->sk_shutdown = sk->sk_shutdown;	newsk->sk_destruct = inet_sock_destruct;	newsk->sk_zapped = 0;	newsk->sk_family = PF_INET;	newsk->sk_protocol = IPPROTO_SCTP;	newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;	newinet = inet_sk(newsk);	/* Initialize sk's sport, dport, rcv_saddr and daddr for	 * getsockname() and getpeername()	 */	newinet->sport = inet->sport;	newinet->saddr = inet->saddr;	newinet->rcv_saddr = inet->rcv_saddr;	newinet->dport = htons(asoc->peer.port);	newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;	newinet->pmtudisc = inet->pmtudisc;      	newinet->id = 0;	newinet->uc_ttl = -1;	newinet->mc_loop = 1;	newinet->mc_ttl = 1;	newinet->mc_index = 0;	newinet->mc_list = NULL;#ifdef INET_REFCNT_DEBUG	atomic_inc(&inet_sock_nr);#endif	if (newsk->sk_prot->init(newsk)) {		sk_common_release(newsk);		newsk = NULL;	}out:	return newsk;}/* Map address, empty for v4 family */static void sctp_v4_addr_v4map(struct sctp_opt *sp, union sctp_addr *addr){	/* Empty */}/* Dump the v4 addr to the seq file. */static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr){	seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr));}/* Event handler for inet address addition/deletion events. * Basically, whenever there is an event, we re-build our local address list. */static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,			       void *ptr){	unsigned long flags;	sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);	__sctp_free_local_addr_list();	__sctp_get_local_addr_list();	sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);	return NOTIFY_DONE;}/* * Initialize the control inode/socket with a control endpoint data * structure.  This endpoint is reserved exclusively for the OOTB processing. */int sctp_ctl_sock_init(void){	int err;	sa_family_t family;	if (sctp_get_pf_specific(PF_INET6))		family = PF_INET6;	else		family = PF_INET;	err = sock_create_kern(family, SOCK_SEQPACKET, IPPROTO_SCTP,			       &sctp_ctl_socket);	if (err < 0) {		printk(KERN_ERR		       "SCTP: Failed to create the SCTP control socket.\n");		return err;	}	sctp_ctl_socket->sk->sk_allocation = GFP_ATOMIC;	inet_sk(sctp_ctl_socket->sk)->uc_ttl = -1;	return 0;}/* Register address family specific functions. */int sctp_register_af(struct sctp_af *af){	switch (af->sa_family) {	case AF_INET:		if (sctp_af_v4_specific)			return 0;		sctp_af_v4_specific = af;		break;	case AF_INET6:		if (sctp_af_v6_specific)			return 0;		sctp_af_v6_specific = af;		break;	default:		return 0;	}	INIT_LIST_HEAD(&af->list);	list_add_tail(&af->list, &sctp_address_families);	return 1;}/* Get the table of functions for manipulating a particular address * family. */struct sctp_af *sctp_get_af_specific(sa_family_t family){	switch (family) {	case AF_INET:		return sctp_af_v4_specific;	case AF_INET6:		return sctp_af_v6_specific;	default:		return NULL;	}}/* Common code to initialize a AF_INET msg_name. */static void sctp_inet_msgname(char *msgname, int *addr_len){	struct sockaddr_in *sin;	sin = (struct sockaddr_in *)msgname;	*addr_len = sizeof(struct sockaddr_in);	sin->sin_family = AF_INET;	memset(sin->sin_zero, 0, sizeof(sin->sin_zero));}/* Copy the primary address of the peer primary address as the msg_name. */static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname,				    int *addr_len){	struct sockaddr_in *sin, *sinfrom;	if (msgname) {		struct sctp_association *asoc;		asoc = event->asoc;		sctp_inet_msgname(msgname, addr_len);		sin = (struct sockaddr_in *)msgname;		sinfrom = &asoc->peer.primary_addr.v4;		sin->sin_port = htons(asoc->peer.port);		sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr;	}}/* Initialize and copy out a msgname from an inbound skb. */static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len){	struct sctphdr *sh;	struct sockaddr_in *sin;	if (msgname) {		sctp_inet_msgname(msgname, len);		sin = (struct sockaddr_in *)msgname;		sh = (struct sctphdr *)skb->h.raw;		sin->sin_port = sh->source;		sin->sin_addr.s_addr = skb->nh.iph->saddr;	}}/* Do we support this AF? */static int sctp_inet_af_supported(sa_family_t family, struct sctp_opt *sp){	/* PF_INET only supports AF_INET addresses. */	return (AF_INET == family);}/* Address matching with wildcards allowed. */static int sctp_inet_cmp_addr(const union sctp_addr *addr1,			      const union sctp_addr *addr2,			      struct sctp_opt *opt){	/* PF_INET only supports AF_INET addresses. */	if (addr1->sa.sa_family != addr2->sa.sa_family)		return 0;	if (INADDR_ANY == addr1->v4.sin_addr.s_addr ||	    INADDR_ANY == addr2->v4.sin_addr.s_addr)		return 1;	if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr)		return 1;	return 0;}/* Verify that provided sockaddr looks bindable.  Common verification has * already been taken care of. */static int sctp_inet_bind_verify(struct sctp_opt *opt, union sctp_addr *addr){	return sctp_v4_available(addr, opt);}/* Verify that sockaddr looks sendable.  Common verification has already * been taken care of. */static int sctp_inet_send_verify(struct sctp_opt *opt, union sctp_addr *addr){	return 1;}/* Fill in Supported Address Type information for INIT and INIT-ACK * chunks.  Returns number of addresses supported. */static int sctp_inet_supported_addrs(const struct sctp_opt *opt,				     __u16 *types){	types[0] = SCTP_PARAM_IPV4_ADDRESS;	return 1;}/* Wrapper routine that calls the ip transmit routine. */static inline int sctp_v4_xmit(struct sk_buff *skb,			       struct sctp_transport *transport, int ipfragok){	SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, "			  "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n",			  __FUNCTION__, skb, skb->len,			  NIPQUAD(((struct rtable *)skb->dst)->rt_src),			  NIPQUAD(((struct rtable *)skb->dst)->rt_dst));	SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);	return ip_queue_xmit(skb, ipfragok);}struct sctp_af sctp_ipv4_specific;static struct sctp_pf sctp_pf_inet = {	.event_msgname = sctp_inet_event_msgname,	.skb_msgname   = sctp_inet_skb_msgname,	.af_supported  = sctp_inet_af_supported,	.cmp_addr      = sctp_inet_cmp_addr,	.bind_verify   = sctp_inet_bind_verify,	.send_verify   = sctp_inet_send_verify,	.supported_addrs = sctp_inet_supported_addrs,	.create_accept_sk = sctp_v4_create_accept_sk,	.addr_v4map	= sctp_v4_addr_v4map,	.af            = &sctp_ipv4_specific,};/* Notifier for inetaddr addition/deletion events.  */struct notifier_block sctp_inetaddr_notifier = {	.notifier_call = sctp_inetaddr_event,};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -