Diff for /embedaddon/mpd/src/l2tp_ctrl.c between versions 1.1.1.2 and 1.1.1.3.2.1

version 1.1.1.2, 2016/11/01 09:56:12 version 1.1.1.3.2.1, 2023/09/27 11:08:00
Line 244  Notes Line 244  Notes
 ************************************************************************/  ************************************************************************/
   
 static int      ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl,  static int      ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl,
                        struct ppp_l2tp_avp_ptrs *ptrs);                        struct ppp_l2tp_avp_ptrs *ptrs,
                         struct ppp_l2tp_avp_list *avps);
 static int      ppp_l2tp_ctrl_setup_2(struct ppp_l2tp_ctrl *ctrl,  static int      ppp_l2tp_ctrl_setup_2(struct ppp_l2tp_ctrl *ctrl,
                         struct ppp_l2tp_avp_ptrs *ptrs);                          struct ppp_l2tp_avp_ptrs *ptrs);
 static void     ppp_l2tp_ctrl_send(struct ppp_l2tp_ctrl *ctrl,  static void     ppp_l2tp_ctrl_send(struct ppp_l2tp_ctrl *ctrl,
Line 379  static const struct l2tp_msg_info ppp_l2tp_msg_info[]  Line 380  static const struct l2tp_msg_info ppp_l2tp_msg_info[] 
             { SS_ESTABLISHED, SS_DYING, -1 },              { SS_ESTABLISHED, SS_DYING, -1 },
             { ORIG_LOCAL, ORIG_REMOTE, -1 }, { SIDE_LAC, -1 },              { ORIG_LOCAL, ORIG_REMOTE, -1 }, { SIDE_LAC, -1 },
             { AVP_ACCM, -1 } },              { AVP_ACCM, -1 } },
        { NULL }        { NULL, 0, NULL, NULL, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0 }, { 0, 0 } }
 };  };
   
 /* Descriptors for each AVP */  /* Descriptors for each AVP */
Line 431  static const struct ppp_l2tp_avp_info ppp_l2tp_avp_inf Line 432  static const struct ppp_l2tp_avp_info ppp_l2tp_avp_inf
 };  };
   
 /* All control connections */  /* All control connections */
struct ghash    *ppp_l2tp_ctrls;static struct ghash   *ppp_l2tp_ctrls;
   
 static uint32_t gNextSerial = 0;  static uint32_t gNextSerial = 0;
   
Line 451  ppp_l2tp_ctrl_create(struct pevent_ctx *ctx, pthread_m Line 452  ppp_l2tp_ctrl_create(struct pevent_ctx *ctx, pthread_m
 {  {
         struct ppp_l2tp_ctrl *ctrl;          struct ppp_l2tp_ctrl *ctrl;
         struct ngm_mkpeer mkpeer;          struct ngm_mkpeer mkpeer;
           unsigned i;
         u_int16_t value16;          u_int16_t value16;
        int index, i;        int index;
                   
         /* Init Call Serial Number */          /* Init Call Serial Number */
         if (gNextSerial == 0)          if (gNextSerial == 0)
Line 558  ppp_l2tp_ctrl_create(struct pevent_ctx *ctx, pthread_m Line 560  ppp_l2tp_ctrl_create(struct pevent_ctx *ctx, pthread_m
                     0, AVP_HOST_NAME, ctrl->self_name, strlen(ctrl->self_name)) == -1)                      0, AVP_HOST_NAME, ctrl->self_name, strlen(ctrl->self_name)) == -1)
                         goto fail;                          goto fail;
         } else {          } else {
            int len = ctrl->avps->avps[index].vlen;            unsigned len = ctrl->avps->avps[index].vlen;
             if (len >= sizeof(ctrl->self_name))              if (len >= sizeof(ctrl->self_name))
                 len = sizeof(ctrl->self_name) - 1;                  len = sizeof(ctrl->self_name) - 1;
             memcpy(ctrl->self_name, ctrl->avps->avps[index].value, len);              memcpy(ctrl->self_name, ctrl->avps->avps[index].value, len);
Line 666  ppp_l2tp_initiate(struct ppp_l2tp_ctrl *ctrl, int out, Line 668  ppp_l2tp_initiate(struct ppp_l2tp_ctrl *ctrl, int out,
 {  {
         struct ppp_l2tp_sess *sess;          struct ppp_l2tp_sess *sess;
         u_int32_t value32;          u_int32_t value32;
        int i;        unsigned i;
   
         /* Debugging */          /* Debugging */
         Log(LOG_DEBUG, ("L2TP: %s invoked, ctrl=%p out=%d", __FUNCTION__, ctrl, out));          Log(LOG_DEBUG, ("L2TP: %s invoked, ctrl=%p out=%d", __FUNCTION__, ctrl, out));
Line 773  ppp_l2tp_connected(struct ppp_l2tp_sess *sess, Line 775  ppp_l2tp_connected(struct ppp_l2tp_sess *sess,
 {  {
         struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;          struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;
         u_int32_t value32;          u_int32_t value32;
        int i;        unsigned i;
   
         /* Debugging */          /* Debugging */
         Log(LOG_DEBUG, ("L2TP: %s invoked, sess=%p", __FUNCTION__, sess));          Log(LOG_DEBUG, ("L2TP: %s invoked, sess=%p", __FUNCTION__, sess));
Line 1029  ppp_l2tp_sess_hooked(struct ppp_l2tp_sess *sess) { Line 1031  ppp_l2tp_sess_hooked(struct ppp_l2tp_sess *sess) {
  */   */
 static int  static int
 ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl,  ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl,
        struct ppp_l2tp_avp_ptrs *ptrs)        struct ppp_l2tp_avp_ptrs *ptrs,
         struct ppp_l2tp_avp_list *avps)
 {  {
         /* Log */          /* Log */
         Log(LOG_INFO, ("L2TP: connected to \"%s\", version=%u.%u",          Log(LOG_INFO, ("L2TP: connected to \"%s\", version=%u.%u",
Line 1090  ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl, Line 1093  ppp_l2tp_ctrl_setup_1(struct ppp_l2tp_ctrl *ctrl,
                 MD5_Update(&md5ctx, &ptrs->challenge->value, ptrs->challenge->length);                  MD5_Update(&md5ctx, &ptrs->challenge->value, ptrs->challenge->length);
                 MD5_Final(hash, &md5ctx);                  MD5_Final(hash, &md5ctx);
   
                if (ppp_l2tp_avp_list_append(ctrl->avps, 0,                if (ppp_l2tp_avp_list_append(avps, 0,
                     0, AVP_CHALLENGE_RESPONSE, hash, sizeof(hash)) == -1)                      0, AVP_CHALLENGE_RESPONSE, hash, sizeof(hash)) == -1)
                 return (0);                  return (0);
         }          }
Line 1750  ppp_l2tp_data_event(void *arg) Line 1753  ppp_l2tp_data_event(void *arg)
         u_int16_t msgtype;          u_int16_t msgtype;
         char ebuf[64];          char ebuf[64];
         int len;          int len;
        int i;        unsigned i, j;
        int j; 
   
         /* Restart idle timer */          /* Restart idle timer */
         pevent_unregister(&ctrl->idle_timer);          pevent_unregister(&ctrl->idle_timer);
Line 1859  ppp_l2tp_data_event(void *arg) Line 1861  ppp_l2tp_data_event(void *arg)
   
                 /* Check for valid control connection state */                  /* Check for valid control connection state */
                 for (i = 0; msg_info->valid_states[i] != -1                  for (i = 0; msg_info->valid_states[i] != -1
                    && msg_info->valid_states[i] != ctrl->state; i++);                    && msg_info->valid_states[i] != (int)ctrl->state; i++);
                 if (msg_info->valid_states[i] == -1) {                  if (msg_info->valid_states[i] == -1) {
   
                         /* Could be in CS_DYING if we just closed the tunnel */                          /* Could be in CS_DYING if we just closed the tunnel */
Line 1918  ppp_l2tp_data_event(void *arg) Line 1920  ppp_l2tp_data_event(void *arg)
   
         /* Check for valid session state, origination, and side */          /* Check for valid session state, origination, and side */
         for (i = 0; msg_info->valid_states[i] != -1          for (i = 0; msg_info->valid_states[i] != -1
            && msg_info->valid_states[i] != sess->state; i++);            && msg_info->valid_states[i] != (int)sess->state; i++);
         if (msg_info->valid_states[i] == -1) {          if (msg_info->valid_states[i] == -1) {
                 snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s",                  snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s",
                     msg_info->name, ppp_l2tp_sess_state_str(sess->state));                      msg_info->name, ppp_l2tp_sess_state_str(sess->state));
Line 1927  ppp_l2tp_data_event(void *arg) Line 1929  ppp_l2tp_data_event(void *arg)
                 goto done;                  goto done;
         }          }
         for (i = 0; msg_info->valid_orig[i] != -1          for (i = 0; msg_info->valid_orig[i] != -1
            && msg_info->valid_orig[i] != sess->orig; i++);            && msg_info->valid_orig[i] != (int)sess->orig; i++);
         if (msg_info->valid_orig[i] == -1) {          if (msg_info->valid_orig[i] == -1) {
                 snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s,"                  snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s,"
                     " but session originated %sly", msg_info->name,                      " but session originated %sly", msg_info->name,
Line 1938  ppp_l2tp_data_event(void *arg) Line 1940  ppp_l2tp_data_event(void *arg)
                 goto done;                  goto done;
         }          }
         for (i = 0; msg_info->valid_side[i] != -1          for (i = 0; msg_info->valid_side[i] != -1
            && msg_info->valid_side[i] != sess->side; i++);            && msg_info->valid_side[i] != (int)sess->side; i++);
         if (msg_info->valid_side[i] == -1) {          if (msg_info->valid_side[i] == -1) {
                 snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s,"                  snprintf(ebuf, sizeof(ebuf), "rec'd %s in state %s,"
                     " but we are %s for this session", msg_info->name,                      " but we are %s for this session", msg_info->name,
Line 2033  ppp_l2tp_handle_SCCRQ(struct ppp_l2tp_ctrl *ctrl, Line 2035  ppp_l2tp_handle_SCCRQ(struct ppp_l2tp_ctrl *ctrl,
         const u_char *tiebreaker;          const u_char *tiebreaker;
         struct ghash_walk walk;          struct ghash_walk walk;
         int diff;          int diff;
        int i;        unsigned i;
   
           (void)avps;
         /* See if there is an outstanding SCCRQ to this peer */          /* See if there is an outstanding SCCRQ to this peer */
         ghash_walk_init(ppp_l2tp_ctrls, &walk);          ghash_walk_init(ppp_l2tp_ctrls, &walk);
         while ((ctrl2 = ghash_walk_next(ppp_l2tp_ctrls, &walk)) != NULL) {          while ((ctrl2 = ghash_walk_next(ppp_l2tp_ctrls, &walk)) != NULL) {
Line 2083  ppp_l2tp_handle_SCCRQ(struct ppp_l2tp_ctrl *ctrl, Line 2086  ppp_l2tp_handle_SCCRQ(struct ppp_l2tp_ctrl *ctrl,
   
 ok:  ok:
         /* Do control connection setup */          /* Do control connection setup */
        if (ppp_l2tp_ctrl_setup_1(ctrl, ptrs) == -1)        if (ppp_l2tp_ctrl_setup_1(ctrl, ptrs, ctrl->avps) == -1)
                 return (-1);                  return (-1);
   
         /* Send response and update state */          /* Send response and update state */
Line 2096  static int Line 2099  static int
 ppp_l2tp_handle_SCCRP(struct ppp_l2tp_ctrl *ctrl,  ppp_l2tp_handle_SCCRP(struct ppp_l2tp_ctrl *ctrl,
         const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)          const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)
 {  {
           struct ppp_l2tp_avp_list *avps0;
   
           (void)avps;
           avps0 = ppp_l2tp_avp_list_create();
   
         /* Do control connection setup */          /* Do control connection setup */
        if (ppp_l2tp_ctrl_setup_1(ctrl, ptrs) == -1)        if ((ppp_l2tp_ctrl_setup_1(ctrl, ptrs, avps0) == -1) ||
             (ppp_l2tp_ctrl_setup_2(ctrl, ptrs) == -1)) {
                 ppp_l2tp_avp_list_destroy(&avps0);
                 return (-1);                  return (-1);
        if (ppp_l2tp_ctrl_setup_2(ctrl, ptrs) == -1)        }
                return (-1); 
   
         /* Send response and update state */          /* Send response and update state */
         ctrl->state = CS_ESTABLISHED;          ctrl->state = CS_ESTABLISHED;
        ppp_l2tp_ctrl_send(ctrl, 0, SCCCN, ctrl->avps);        ppp_l2tp_ctrl_send(ctrl, 0, SCCCN, avps0);
         if (*ctrl->cb->ctrl_connected != NULL)          if (*ctrl->cb->ctrl_connected != NULL)
             (*ctrl->cb->ctrl_connected)(ctrl);              (*ctrl->cb->ctrl_connected)(ctrl);
           ppp_l2tp_avp_list_destroy(&avps0);
         return (0);          return (0);
 }  }
   
Line 2114  static int Line 2124  static int
 ppp_l2tp_handle_SCCCN(struct ppp_l2tp_ctrl *ctrl,  ppp_l2tp_handle_SCCCN(struct ppp_l2tp_ctrl *ctrl,
         const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)          const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)
 {  {
           (void)avps;
         /* Do control connection setup */          /* Do control connection setup */
         if (ppp_l2tp_ctrl_setup_2(ctrl, ptrs) == -1)          if (ppp_l2tp_ctrl_setup_2(ctrl, ptrs) == -1)
                 return (-1);                  return (-1);
Line 2132  ppp_l2tp_handle_StopCCN(struct ppp_l2tp_ctrl *ctrl, Line 2143  ppp_l2tp_handle_StopCCN(struct ppp_l2tp_ctrl *ctrl,
         struct ppp_l2tp_sess *sess;          struct ppp_l2tp_sess *sess;
         struct ghash_walk walk;          struct ghash_walk walk;
   
           (void)avps;
         /* StopCCN implies closing all sessions */          /* StopCCN implies closing all sessions */
         ctrl->peer_notified = 1;          ctrl->peer_notified = 1;
         ghash_walk_init(ctrl->sessions, &walk);          ghash_walk_init(ctrl->sessions, &walk);
Line 2148  static int Line 2160  static int
 ppp_l2tp_handle_HELLO(struct ppp_l2tp_ctrl *ctrl,  ppp_l2tp_handle_HELLO(struct ppp_l2tp_ctrl *ctrl,
         const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)          const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)
 {  {
           (void)avps;
           (void)ctrl;
           (void)ptrs;
         return (0);          return (0);
 }  }
   
Line 2204  static int Line 2219  static int
 ppp_l2tp_handle_OCRP(struct ppp_l2tp_sess *sess,  ppp_l2tp_handle_OCRP(struct ppp_l2tp_sess *sess,
         const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)          const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)
 {  {
           (void)avps;
         if (sess->state == SS_DYING)          if (sess->state == SS_DYING)
                 return (0);                  return (0);
   
Line 2240  ppp_l2tp_handle_ICRP(struct ppp_l2tp_sess *sess, Line 2256  ppp_l2tp_handle_ICRP(struct ppp_l2tp_sess *sess,
         struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;          struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;
         char buf[64];          char buf[64];
                   
           (void)avps;
         if (sess->state == SS_DYING)          if (sess->state == SS_DYING)
                 return (0);                  return (0);
   
Line 2268  static int Line 2285  static int
 ppp_l2tp_handle_CDN(struct ppp_l2tp_sess *sess,  ppp_l2tp_handle_CDN(struct ppp_l2tp_sess *sess,
         const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)          const struct ppp_l2tp_avp_list *avps, struct ppp_l2tp_avp_ptrs *ptrs)
 {  {
           (void)avps;
         sess->peer_notified = 1;          sess->peer_notified = 1;
         ppp_l2tp_sess_close(sess, ptrs->errresultcode->result,          ppp_l2tp_sess_close(sess, ptrs->errresultcode->result,
             ptrs->errresultcode->error, ptrs->errresultcode->errmsg);              ptrs->errresultcode->error, ptrs->errresultcode->errmsg);
Line 2280  ppp_l2tp_handle_SLI(struct ppp_l2tp_sess *sess, Line 2298  ppp_l2tp_handle_SLI(struct ppp_l2tp_sess *sess,
 {  {
         struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;          struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;
   
           (void)avps;
         if (sess->state == SS_DYING)          if (sess->state == SS_DYING)
                 return (0);                  return (0);
   
Line 2295  ppp_l2tp_handle_WEN(struct ppp_l2tp_sess *sess, Line 2314  ppp_l2tp_handle_WEN(struct ppp_l2tp_sess *sess,
 {  {
         struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;          struct ppp_l2tp_ctrl *const ctrl = sess->ctrl;
   
           (void)avps;
         if (sess->state == SS_DYING)          if (sess->state == SS_DYING)
                 return (0);                  return (0);
   
Line 2482  ppp_l2tp_ctrl_equal(struct ghash *g, const void *item1 Line 2502  ppp_l2tp_ctrl_equal(struct ghash *g, const void *item1
         const struct ppp_l2tp_ctrl *const ctrl1 = item1;          const struct ppp_l2tp_ctrl *const ctrl1 = item1;
         const struct ppp_l2tp_ctrl *const ctrl2 = item2;          const struct ppp_l2tp_ctrl *const ctrl2 = item2;
   
           (void)g;
         return (ctrl1->config.tunnel_id == ctrl2->config.tunnel_id);          return (ctrl1->config.tunnel_id == ctrl2->config.tunnel_id);
 }  }
   
Line 2490  ppp_l2tp_ctrl_hash(struct ghash *g, const void *item) Line 2511  ppp_l2tp_ctrl_hash(struct ghash *g, const void *item)
 {  {
         const struct ppp_l2tp_ctrl *const ctrl = item;          const struct ppp_l2tp_ctrl *const ctrl = item;
   
           (void)g;
         return ((u_int32_t)ctrl->config.tunnel_id);          return ((u_int32_t)ctrl->config.tunnel_id);
 }  }
   
Line 2499  ppp_l2tp_sess_equal(struct ghash *g, const void *item1 Line 2521  ppp_l2tp_sess_equal(struct ghash *g, const void *item1
         const struct ppp_l2tp_sess *const sess1 = item1;          const struct ppp_l2tp_sess *const sess1 = item1;
         const struct ppp_l2tp_sess *const sess2 = item2;          const struct ppp_l2tp_sess *const sess2 = item2;
   
           (void)g;
         return (sess1->config.session_id == sess2->config.session_id);          return (sess1->config.session_id == sess2->config.session_id);
 }  }
   
Line 2507  ppp_l2tp_sess_hash(struct ghash *g, const void *item) Line 2530  ppp_l2tp_sess_hash(struct ghash *g, const void *item)
 {  {
         const struct ppp_l2tp_sess *const sess = item;          const struct ppp_l2tp_sess *const sess = item;
   
           (void)g;
         return ((u_int32_t)sess->config.session_id);          return ((u_int32_t)sess->config.session_id);
 }  }
   
Line 2523  ppp_l2tp_ctrl_dump(struct ppp_l2tp_ctrl *ctrl, Line 2547  ppp_l2tp_ctrl_dump(struct ppp_l2tp_ctrl *ctrl,
 {  {
         char buf[1024];          char buf[1024];
         va_list args;          va_list args;
        int i;        unsigned i;
 
         (void)ctrl;
 
         if ((gLogOptions & LOG_DEBUG) == 0)
                 return;
   
         va_start(args, fmt);          va_start(args, fmt);
         vsnprintf(buf, sizeof(buf), fmt, args);          vsnprintf(buf, sizeof(buf), fmt, args);

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3.2.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>