···161161 */162162 int sndbuf_policy;163163164164+ /*165165+ * Policy for preforming sctp/socket accounting166166+ * 0 - do socket level accounting, all assocs share sk_rcvbuf167167+ * 1 - do sctp accounting, each asoc may use sk_rcvbuf bytes168168+ */169169+ int rcvbuf_policy;170170+164171 /* Delayed SACK timeout 200ms default*/165172 int sack_timeout;166173···225218#define sctp_cookie_preserve_enable (sctp_globals.cookie_preserve_enable)226219#define sctp_max_retrans_association (sctp_globals.max_retrans_association)227220#define sctp_sndbuf_policy (sctp_globals.sndbuf_policy)221221+#define sctp_rcvbuf_policy (sctp_globals.rcvbuf_policy)228222#define sctp_max_retrans_path (sctp_globals.max_retrans_path)229223#define sctp_max_retrans_init (sctp_globals.max_retrans_init)230224#define sctp_sack_timeout (sctp_globals.sack_timeout)···12301222 int last_key;12311223 int key_changed_at;1232122412331233- /* Default timeouts. */12341234- int timeouts[SCTP_NUM_TIMEOUT_TYPES];12351235-12361225 /* sendbuf acct. policy. */12371226 __u32 sndbuf_policy;12271227+12281228+ /* rcvbuf acct. policy. */12291229+ __u32 rcvbuf_policy;12381230};1239123112401232/* Recover the outter endpoint structure. */···15601552 * as specified in the sk->sndbuf.15611553 */15621554 int sndbuf_used;15551555+15561556+ /* This is the amount of memory that this association has allocated15571557+ * in the receive path at any given time.15581558+ */15591559+ atomic_t rmem_alloc;1563156015641561 /* This is the wait queue head for send requests waiting on15651562 * the association sndbuf space.
+6-2
net/ipv6/af_inet6.c
···699699 /* Register the family here so that the init calls below will700700 * be able to create sockets. (?? is this dangerous ??)701701 */702702- (void) sock_register(&inet6_family_ops);702702+ err = sock_register(&inet6_family_ops);703703+ if (err)704704+ goto out_unregister_raw_proto;703705704706 /* Initialise ipv6 mibs */705707 err = init_ipv6_mibs();706708 if (err)707707- goto out_unregister_raw_proto;709709+ goto out_unregister_sock;708710709711 /*710712 * ipngwg API draft makes clear that the correct semantics···798796 ipv6_sysctl_unregister();799797#endif800798 cleanup_ipv6_mibs();799799+out_unregister_sock:800800+ sock_unregister(PF_INET6);801801out_unregister_raw_proto:802802 proto_unregister(&rawv6_prot);803803out_unregister_udp_proto:
+29-4
net/sctp/associola.c
···128128 */129129 asoc->max_burst = sctp_max_burst;130130131131- /* Copy things from the endpoint. */131131+ /* initialize association timers */132132+ asoc->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0;133133+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial;134134+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial;135135+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = asoc->rto_initial;136136+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0;137137+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = 0;138138+139139+ /* sctpimpguide Section 2.12.2140140+ * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the141141+ * recommended value of 5 times 'RTO.Max'.142142+ */143143+ asoc->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]144144+ = 5 * asoc->rto_max;145145+146146+ asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;147147+ asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =148148+ SCTP_DEFAULT_TIMEOUT_SACK;149149+ asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] =150150+ sp->autoclose * HZ;151151+152152+ /* Initilizes the timers */132153 for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) {133133- asoc->timeouts[i] = ep->timeouts[i];134154 init_timer(&asoc->timers[i]);135155 asoc->timers[i].function = sctp_timer_events[i];136156 asoc->timers[i].data = (unsigned long) asoc;···177157 * RFC 6 - A SCTP receiver MUST be able to receive a minimum of178158 * 1500 bytes in one SCTP packet.179159 */180180- if (sk->sk_rcvbuf < SCTP_DEFAULT_MINWINDOW)160160+ if ((sk->sk_rcvbuf/2) < SCTP_DEFAULT_MINWINDOW)181161 asoc->rwnd = SCTP_DEFAULT_MINWINDOW;182162 else183183- asoc->rwnd = sk->sk_rcvbuf;163163+ asoc->rwnd = sk->sk_rcvbuf/2;184164185165 asoc->a_rwnd = asoc->rwnd;186166···191171192172 /* Set the sndbuf size for transmit. */193173 asoc->sndbuf_used = 0;174174+175175+ /* Initialize the receive memory counter */176176+ atomic_set(&asoc->rmem_alloc, 0);194177195178 init_waitqueue_head(&asoc->wait);196179···402379 idr_remove(&sctp_assocs_id, asoc->assoc_id);403380 spin_unlock_bh(&sctp_assocs_id_lock);404381 }382382+383383+ BUG_TRAP(!atomic_read(&asoc->rmem_alloc));405384406385 if (asoc->base.malloced) {407386 kfree(asoc);
+3-23
net/sctp/endpointola.c
···7070 struct sock *sk,7171 gfp_t gfp)7272{7373- struct sctp_sock *sp = sctp_sk(sk);7473 memset(ep, 0, sizeof(struct sctp_endpoint));75747675 /* Initialize the base structure. */···99100 /* Create the lists of associations. */100101 INIT_LIST_HEAD(&ep->asocs);101102102102- /* Set up the base timeout information. */103103- ep->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0;104104- ep->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =105105- msecs_to_jiffies(sp->rtoinfo.srto_initial);106106- ep->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =107107- msecs_to_jiffies(sp->rtoinfo.srto_initial);108108- ep->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] =109109- msecs_to_jiffies(sp->rtoinfo.srto_initial);110110- ep->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0;111111- ep->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = 0;112112-113113- /* sctpimpguide-05 Section 2.12.2114114- * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the115115- * recommended value of 5 times 'RTO.Max'.116116- */117117- ep->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]118118- = 5 * msecs_to_jiffies(sp->rtoinfo.srto_max);119119-120120- ep->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;121121- ep->timeouts[SCTP_EVENT_TIMEOUT_SACK] = sctp_sack_timeout;122122- ep->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sp->autoclose * HZ;123123-124103 /* Use SCTP specific send buffer space queues. */125104 ep->sndbuf_policy = sctp_sndbuf_policy;126105 sk->sk_write_space = sctp_write_space;127106 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);107107+108108+ /* Get the receive buffer policy for this endpoint */109109+ ep->rcvbuf_policy = sctp_rcvbuf_policy;128110129111 /* Initialize the secret key used with cookie. */130112 get_random_bytes(&ep->secret_key[0], SCTP_SECRET_SIZE);
-20
net/sctp/input.c
···100100 return 0;101101}102102103103-/* The free routine for skbuffs that sctp receives */104104-static void sctp_rfree(struct sk_buff *skb)105105-{106106- atomic_sub(sizeof(struct sctp_chunk),&skb->sk->sk_rmem_alloc);107107- sock_rfree(skb);108108-}109109-110110-/* The ownership wrapper routine to do receive buffer accounting */111111-static void sctp_rcv_set_owner_r(struct sk_buff *skb, struct sock *sk)112112-{113113- skb_set_owner_r(skb,sk);114114- skb->destructor = sctp_rfree;115115- atomic_add(sizeof(struct sctp_chunk),&sk->sk_rmem_alloc);116116-}117117-118103struct sctp_input_cb {119104 union {120105 struct inet_skb_parm h4;···202217 rcvr = &ep->base;203218 }204219205205- if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf)206206- goto discard_release;207207-208220 /*209221 * RFC 2960, 8.4 - Handle "Out of the blue" Packets.210222 * An SCTP packet is called an "out of the blue" (OOTB)···237255 goto discard_release;238256 }239257 SCTP_INPUT_CB(skb)->chunk = chunk;240240-241241- sctp_rcv_set_owner_r(skb,sk);242258243259 /* Remember what endpoint is to handle this packet. */244260 chunk->rcvr = rcvr;
···385385 NULL,386386 sctp_generate_t4_rto_event,387387 sctp_generate_t5_shutdown_guard_event,388388- sctp_generate_heartbeat_event,388388+ NULL,389389 sctp_generate_sack_event,390390 sctp_generate_autoclose_event,391391};···689689 * increased due to timer expirations.690690 */691691 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =692692- asoc->ep->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT];692692+ asoc->rto_initial;693693 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =694694- asoc->ep->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE];694694+ asoc->rto_initial;695695 }696696697697 if (sctp_state(asoc, ESTABLISHED) ||
+22
net/sctp/sm_statefuns.c
···51605160 sctp_verb_t deliver;51615161 int tmp;51625162 __u32 tsn;51635163+ int account_value;51645164+ struct sock *sk = asoc->base.sk;5163516551645166 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;51655167 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));···51705168 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);5171516951725170 /* ASSERT: Now skb->data is really the user data. */51715171+51725172+ /*51735173+ * if we are established, and we have used up our receive51745174+ * buffer memory, drop the frame51755175+ */51765176+ if (asoc->state == SCTP_STATE_ESTABLISHED) {51775177+ /*51785178+ * If the receive buffer policy is 1, then each51795179+ * association can allocate up to sk_rcvbuf bytes51805180+ * otherwise, all the associations in aggregate51815181+ * may allocate up to sk_rcvbuf bytes51825182+ */51835183+ if (asoc->ep->rcvbuf_policy)51845184+ account_value = atomic_read(&asoc->rmem_alloc);51855185+ else51865186+ account_value = atomic_read(&sk->sk_rmem_alloc);51875187+51885188+ if (account_value > sk->sk_rcvbuf)51895189+ return SCTP_IERROR_IGNORE_TSN;51905190+ }5173519151745192 /* Process ECN based congestion.51755193 *
···5252 struct sctp_association *asoc);5353static void sctp_ulpevent_release_data(struct sctp_ulpevent *event);54545555-/* Stub skb destructor. */5656-static void sctp_stub_rfree(struct sk_buff *skb)5757-{5858-/* WARNING: This function is just a warning not to use the5959- * skb destructor. If the skb is shared, we may get the destructor6060- * callback on some processor that does not own the sock_lock. This6161- * was occuring with PACKET socket applications that were monitoring6262- * our skbs. We can't take the sock_lock, because we can't risk6363- * recursing if we do really own the sock lock. Instead, do all6464- * of our rwnd manipulation while we own the sock_lock outright.6565- */6666-}6767-6855/* Initialize an ULP event from an given skb. */6956SCTP_STATIC void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)7057{···98111 */99112 sctp_association_hold((struct sctp_association *)asoc);100113 skb = sctp_event2skb(event);101101- skb->sk = asoc->base.sk;102114 event->asoc = (struct sctp_association *)asoc;103103- skb->destructor = sctp_stub_rfree;115115+ atomic_add(skb->truesize, &event->asoc->rmem_alloc);116116+ skb_set_owner_r(skb, asoc->base.sk);104117}105118106119/* A simple destructor to give up the reference to the association. */107120static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)108121{109109- sctp_association_put(event->asoc);122122+ struct sctp_association *asoc = event->asoc;123123+ struct sk_buff *skb = sctp_event2skb(event);124124+125125+ atomic_sub(skb->truesize, &asoc->rmem_alloc);126126+ sctp_association_put(asoc);110127}111128112129/* Create and initialize an SCTP_ASSOC_CHANGE event.···913922/* Free a ulpevent that has an owner. It includes releasing the reference914923 * to the owner, updating the rwnd in case of a DATA event and freeing the915924 * skb.916916- * See comments in sctp_stub_rfree().917925 */918926void sctp_ulpevent_free(struct sctp_ulpevent *event)919927{