sctp: introduce sctp_assoc_update_frag_point
and avoid the open-coded versions of it. Now sctp_datamsg_from_user can just re-use asoc->frag_point as it will always be updated. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									feddd6c1af
								
							
						
					
					
						commit
						2f5e3c9df6
					
				| @ -428,26 +428,6 @@ static inline int sctp_list_single_entry(struct list_head *head) | ||||
| 	return (head->next != head) && (head->next == head->prev); | ||||
| } | ||||
| 
 | ||||
| /* Break down data chunks at this point.  */ | ||||
| static inline int sctp_frag_point(const struct sctp_association *asoc, int pmtu) | ||||
| { | ||||
| 	struct sctp_sock *sp = sctp_sk(asoc->base.sk); | ||||
| 	struct sctp_af *af = sp->pf->af; | ||||
| 	int frag = pmtu; | ||||
| 
 | ||||
| 	frag -= af->ip_options_len(asoc->base.sk); | ||||
| 	frag -= af->net_header_len; | ||||
| 	frag -= sizeof(struct sctphdr) + sctp_datachk_len(&asoc->stream); | ||||
| 
 | ||||
| 	if (asoc->user_frag) | ||||
| 		frag = min_t(int, frag, asoc->user_frag); | ||||
| 
 | ||||
| 	frag = SCTP_TRUNC4(min_t(int, frag, SCTP_MAX_CHUNK_LEN - | ||||
| 					    sctp_datachk_len(&asoc->stream))); | ||||
| 
 | ||||
| 	return frag; | ||||
| } | ||||
| 
 | ||||
| static inline void sctp_assoc_pending_pmtu(struct sctp_association *asoc) | ||||
| { | ||||
| 	sctp_assoc_sync_pmtu(asoc); | ||||
|  | ||||
| @ -2097,6 +2097,7 @@ int sctp_assoc_update(struct sctp_association *old, | ||||
| 
 | ||||
| __u32 sctp_association_get_next_tsn(struct sctp_association *); | ||||
| 
 | ||||
| void sctp_assoc_update_frag_point(struct sctp_association *asoc); | ||||
| void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu); | ||||
| void sctp_assoc_sync_pmtu(struct sctp_association *asoc); | ||||
| void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int); | ||||
|  | ||||
| @ -666,8 +666,6 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, | ||||
| 
 | ||||
| 	peer->pmtu_pending = 0; | ||||
| 
 | ||||
| 	asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu); | ||||
| 
 | ||||
| 	/* The asoc->peer.port might not be meaningful yet, but
 | ||||
| 	 * initialize the packet structure anyway. | ||||
| 	 */ | ||||
| @ -1370,10 +1368,26 @@ sctp_assoc_choose_alter_transport(struct sctp_association *asoc, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void sctp_assoc_update_frag_point(struct sctp_association *asoc) | ||||
| { | ||||
| 	int frag = sctp_mtu_payload(sctp_sk(asoc->base.sk), asoc->pathmtu, | ||||
| 				    sctp_datachk_len(&asoc->stream)); | ||||
| 
 | ||||
| 	if (asoc->user_frag) | ||||
| 		frag = min_t(int, frag, asoc->user_frag); | ||||
| 
 | ||||
| 	frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN - | ||||
| 				sctp_datachk_len(&asoc->stream)); | ||||
| 
 | ||||
| 	asoc->frag_point = SCTP_TRUNC4(frag); | ||||
| } | ||||
| 
 | ||||
| void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu) | ||||
| { | ||||
| 	if (asoc->pathmtu != pmtu) | ||||
| 	if (asoc->pathmtu != pmtu) { | ||||
| 		asoc->pathmtu = pmtu; | ||||
| 		sctp_assoc_update_frag_point(asoc); | ||||
| 	} | ||||
| 
 | ||||
| 	pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc, | ||||
| 		 asoc->pathmtu, asoc->frag_point); | ||||
| @ -1403,10 +1417,6 @@ void sctp_assoc_sync_pmtu(struct sctp_association *asoc) | ||||
| 	} | ||||
| 
 | ||||
| 	sctp_assoc_set_pmtu(asoc, pmtu); | ||||
| 	asoc->frag_point = sctp_frag_point(asoc, pmtu); | ||||
| 
 | ||||
| 	pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc, | ||||
| 		 asoc->pathmtu, asoc->frag_point); | ||||
| } | ||||
| 
 | ||||
| /* Should we send a SACK to update our peer? */ | ||||
|  | ||||
| @ -172,8 +172,6 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, | ||||
| 	struct list_head *pos, *temp; | ||||
| 	struct sctp_chunk *chunk; | ||||
| 	struct sctp_datamsg *msg; | ||||
| 	struct sctp_sock *sp; | ||||
| 	struct sctp_af *af; | ||||
| 	int err; | ||||
| 
 | ||||
| 	msg = sctp_datamsg_new(GFP_KERNEL); | ||||
| @ -192,12 +190,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, | ||||
| 	/* This is the biggest possible DATA chunk that can fit into
 | ||||
| 	 * the packet | ||||
| 	 */ | ||||
| 	sp = sctp_sk(asoc->base.sk); | ||||
| 	af = sp->pf->af; | ||||
| 	max_data = asoc->pathmtu - af->net_header_len - | ||||
| 		   sizeof(struct sctphdr) - sctp_datachk_len(&asoc->stream) - | ||||
| 		   af->ip_options_len(asoc->base.sk); | ||||
| 	max_data = SCTP_TRUNC4(max_data); | ||||
| 	max_data = asoc->frag_point; | ||||
| 
 | ||||
| 	/* If the the peer requested that we authenticate DATA chunks
 | ||||
| 	 * we need to account for bundling of the AUTH chunks along with | ||||
| @ -222,9 +215,6 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/* Check what's our max considering the above */ | ||||
| 	max_data = min_t(size_t, max_data, asoc->frag_point); | ||||
| 
 | ||||
| 	/* Set first_len and then account for possible bundles on first frag */ | ||||
| 	first_len = max_data; | ||||
| 
 | ||||
|  | ||||
| @ -3251,7 +3251,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned | ||||
| 			       sctp_datachk_len(&asoc->stream); | ||||
| 		} | ||||
| 		asoc->user_frag = val; | ||||
| 		asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu); | ||||
| 		sctp_assoc_update_frag_point(asoc); | ||||
| 	} else { | ||||
| 		if (params.assoc_id && sctp_style(sk, UDP)) | ||||
| 			return -EINVAL; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user