📄 sctp_t.c
字号:
if ( !ops || ops->titvl ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_THROTTLE_ITVL; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sctp_default_throttle_itvl*1000/HZ; } if ( !ops || ops->hmac ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_MAC_TYPE; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sctp_default_mac_type; } if ( !ops || ops->mseg ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_MAXSEG; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = 576; } if ( !ops || ops->debug ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_DEBUG; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = 0; }}/* * Size and Build Current options * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Either builds the current options requested or builds all current options. */static size_t sctp_current_opts_size(sctp_t *sp, sctp_opts_t *ops){ size_t len = 0; const size_t hlen = sizeof(struct t_opthdr); const size_t olen = hlen + sizeof(t_scalar_t); if ( !ops || ops->bcast ) { len += olen; } if ( !ops || ops->norte ) { len += olen; } if ( !ops || ops->opts ) { len += olen; } if ( !ops || ops->reuse ) { len += olen; } if ( !ops || ops->tos ) { len += olen; } if ( !ops || ops->ttl ) { len += olen; } if ( !ops || ops->nd ) { len += olen; } if ( !ops || ops->cork ) { len += olen; } if ( !ops || ops->ppi ) { len += olen; } if ( !ops || ops->sid ) { len += olen; } if ( !ops || ops->ropt ) { len += olen; } if ( !ops || ops->cklife ) { len += olen; } if ( !ops || ops->sack ) { len += olen; } if ( !ops || ops->path ) { len += olen; } if ( !ops || ops->assoc ) { len += olen; } if ( !ops || ops->init ) { len += olen; } if ( !ops || ops->hbitvl ) { len += olen; } if ( !ops || ops->rtoinit ) { len += olen; } if ( !ops || ops->rtomin ) { len += olen; } if ( !ops || ops->rtomax ) { len += olen; } if ( !ops || ops->ostr ) { len += olen; } if ( !ops || ops->istr ) { len += olen; } if ( !ops || ops->ckinc ) { len += olen; } if ( !ops || ops->titvl ) { len += olen; } if ( !ops || ops->hmac ) { len += olen; } if ( !ops || ops->mseg ) { len += olen; } if ( !ops || ops->debug ) { len += olen; } if ( !ops || ops->hb ) { size_t n = ops ? (ops->hb->len - hlen)/sizeof(t_sctp_hb_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) len += hlen + n * sizeof(t_sctp_hb_t); } if ( !ops || ops->rto ) { size_t n = ops ? (ops->rto->len - hlen)/sizeof(t_sctp_rto_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) len += hlen + n * sizeof(t_sctp_rto_t); } if ( !ops || ops->status ) { size_t n = ops ? (ops->status->len - hlen - sizeof(t_sctp_status_t))/sizeof(t_sctp_dest_status_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) len += hlen + sizeof(t_sctp_status_t) + n * sizeof(t_sctp_dest_status_t); } return(len);}static void sctp_build_current_opts(sctp_t *sp, sctp_opts_t *ops, unsigned char **p){ struct t_opthdr *oh; const size_t hlen = sizeof(*oh); const size_t olen = hlen + sizeof(t_scalar_t); if ( !ops || ops->bcast ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_BROADCAST; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->ip_broadcast ? T_YES : T_NO; } if ( !ops || ops->norte ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_DONTROUTE; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->ip_dontroute ? T_YES : T_NO; } if ( !ops || ops->opts ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_OPTIONS; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = 0; } if ( !ops || ops->reuse ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_REUSEADDR; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->i_flags & TF_IP_REUSEADDR ? T_YES : T_NO; } if ( !ops || ops->tos ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_TOS; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->ip_tos; } if ( !ops || ops->ttl ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_IP; oh->name = T_IP_TTL; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->ip_ttl; } if ( !ops || ops->nd ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_NODELAY; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->options & SCTP_OPTION_NAGLE ? T_NO : T_YES; } if ( !ops || ops->cork ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_CORK; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->options & SCTP_OPTION_CORK ? T_YES : T_NO; } if ( !ops || ops->ppi ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_PPI; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->ppi; } if ( !ops || ops->sid ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_SID; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->sid; } /* note ssn and tsn are per-packet */ if ( !ops || ops->ropt ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_RECVOPT; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->i_flags & TF_SCTP_RECVOPT ? T_YES : T_NO; } if ( !ops || ops->cklife ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_COOKIE_LIFE; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->ck_life*1000+HZ-1)/HZ; } if ( !ops || ops->sack ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_SACK_DELAY; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->max_sack*1000+HZ-1)/HZ; } if ( !ops || ops->path ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_PATH_MAX_RETRANS; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->rtx_path; } if ( !ops || ops->assoc ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_ASSOC_MAX_RETRANS; oh->status = T_SUCCESS; *((t_uscalar_t *)*p)++ = sp->max_retrans; } if ( !ops || ops->init ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_MAX_INIT_RETRIES; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->max_inits; } if ( !ops || ops->hbitvl ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_HEARTBEAT_ITVL; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->hb_itvl*1000+HZ-1)/HZ; } if ( !ops || ops->rtoinit ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_RTO_INITIAL; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->rto_ini*1000+HZ-1)/HZ; } if ( !ops || ops->rtomin ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_RTO_MIN; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->rto_min*1000+HZ-1)/HZ; } if ( !ops || ops->rtomax ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_RTO_MAX; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->rto_max*1000+HZ-1)/HZ; } if ( !ops || ops->ostr ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_OSTREAMS; oh->status = T_SUCCESS; if ( (1<<sp->i_state) & (TSF_DATA_XFER|TSF_WIND_ORDREL|TSF_WREQ_ORDREL) ) *((t_scalar_t *)*p)++ = sp->n_ostr; else *((t_scalar_t *)*p)++ = sp->req_ostr; } if ( !ops || ops->istr ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_ISTREAMS; oh->status = T_SUCCESS; if ( (1<<sp->i_state) & (TSF_DATA_XFER|TSF_WIND_ORDREL|TSF_WREQ_ORDREL) ) *((t_scalar_t *)*p)++ = sp->n_istr; else *((t_scalar_t *)*p)++ = sp->max_istr; } if ( !ops || ops->ckinc ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_COOKIE_INC; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->ck_inc*1000+HZ-1)/HZ; } if ( !ops || ops->titvl ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_THROTTLE_ITVL; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = (sp->throttle*1000+HZ-1)/HZ; } if ( !ops || ops->hmac ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_MAC_TYPE; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->hmac; } if ( !ops || ops->mseg ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_MAXSEG; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->pmtu; } if ( !ops || ops->debug ) { oh = ((struct t_opthdr *)*p)++; oh->len = olen; oh->level = T_INET_SCTP; oh->name = T_SCTP_DEBUG; oh->status = T_SUCCESS; *((t_scalar_t *)*p)++ = sp->options; } if ( !ops || ops->hb ) { size_t n = ops ? (ops->hb->len - hlen)/sizeof(t_sctp_hb_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) { sctp_daddr_t *sd; oh = ((struct t_opthdr *)*p)++; oh->len = sizeof(*oh) + n * sizeof(t_sctp_hb_t); oh->level = T_INET_SCTP; oh->name = T_SCTP_HB; oh->status = T_SUCCESS; for ( sd = sp->daddr; n && sd; n--, sd = sd->next ) { t_sctp_hb_t *hb = ((t_sctp_hb_t *)*p)++; hb->hb_dest = sd->daddr; hb->hb_onoff = sd->hb_onoff; hb->hb_itvl = (sd->hb_itvl*1000+HZ-1)/HZ; } } } if ( !ops || ops->rto ) { size_t n = ops ? (ops->rto->len - hlen)/sizeof(t_sctp_rto_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) { sctp_daddr_t *sd; oh = ((struct t_opthdr *)*p)++; oh->len = sizeof(*oh) + n * sizeof(t_sctp_rto_t); oh->level = T_INET_SCTP; oh->name = T_SCTP_RTO; oh->status = T_SUCCESS; for ( sd = sp->daddr; n && sd; n--, sd = sd->next ) { t_sctp_rto_t *rto = ((t_sctp_rto_t *)*p)++; rto->rto_dest = sd->daddr; rto->rto_initial = (sp->rto_ini*1000+HZ-1)/HZ; rto->rto_min = (sd->rto_min*1000+HZ-1)/HZ; rto->rto_max = (sd->rto_max*1000+HZ-1)/HZ; rto->max_retrans = sd->max_retrans; } } } if ( !ops || ops->status ) { size_t n = ops ? (ops->status->len - hlen - sizeof(t_sctp_status_t))/ sizeof(t_sctp_dest_status_t) : sp->danum; if ( !n ) n = sp->danum; if ( n ) { sctp_daddr_t *sd; t_sctp_status_t *curr; oh = ((struct t_opthdr *)*p)++; oh->len = sizeof(*oh) + sizeof(t_sctp_status_t) + n * sizeof(t_sctp_dest_status_t); oh->level = T_INET_SCTP; oh->name = T_SCTP_STATUS; oh->status = T_SUCCESS; curr = ((t_sctp_status_t *)*p)++; curr->curr_rwnd = sp->p_rwnd - sp->in_flight; curr->curr_rbuf = sp->a_rwnd; curr->curr_nrep = n; for ( sd = sp->daddr; n && sd; n--, sd = sd->next ) { t_sctp_dest_status_t *dest = ((t_sctp_dest_status_t *)*p)++; dest->dest_addr = sd->daddr; dest->dest_cwnd = sd->cwnd; dest->dest_unack = sd->in_flight; dest->dest_srtt = (sd->srtt*1000+HZ-1)/HZ; dest->dest_rvar = sd->rttvar; dest->dest_rto = (sd->rto*1000+HZ-1)/HZ; dest->dest_sst = sd->ssthresh; } } }}/* * Size and Build Checked or Negotiated options * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Builds the checked or negotiated options. */static size_t sctp_set_opts_size(sctp_t *sp, sctp_opts_t *ops){ size_t len = 0; const size_t hlen = sizeof(struct t_opthdr); const size_t olen = hlen + sizeof(t_scalar_t); if ( ops->bcast ) { len += olen; } if ( ops->norte ) { len += olen; } if ( ops->opts ) { len += olen; } if ( ops->reuse ) { len += olen; } if ( ops->tos ) { len += olen; } if ( ops->ttl ) { len += olen; } if ( ops->nd ) { len += olen; } if ( ops->cork ) { len += olen; } if ( ops->ppi ) { len += olen; } if ( ops->sid ) { len += olen; } if ( ops->ssn ) { len += olen; } if ( ops->tsn ) { len += olen; } if ( ops->ropt ) { len += olen; } if ( ops->cklife ) { len += olen; } if ( ops->sack ) { len += olen; } if ( ops->path ) { len += olen; } if ( ops->assoc ) { len += olen; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -