Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

ikev2
Wednesday, September 22nd, 2010 at 9:00:24am MDT 

  1. diff --git src/message.c src/message.c
  2. index 1892a33..3dea0d2 100644
  3. --- src/message.c
  4. +++ src/message.c
  5. @@ -1306,8 +1306,33 @@ guint32 message_ike_auth_i_payload_next(struct session *session, guint32 curr)
  6.  
  7.  #ifdef MOBIKE
  8.         case (N_MOBIKE_SUPPORTED << 8 | IKEV2_PAYLOAD_NOTIFY):
  9. -              next = IKEV2_PAYLOAD_SA;
  10. +
  11. +              if(session->local_ipv4_addresses_ptr)
  12. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  13. +              else if(session->local_ipv6_addresses_ptr)
  14. +                     next = (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  15. +              else
  16. +                     next = IKEV2_PAYLOAD_SA;
  17.                break;
  18. +
  19. +       case (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  20. +
  21. +              if(session->local_ipv4_addresses_ptr->next)
  22. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  23. +              else if(session->local_ipv6_addresses_ptr)
  24. +                     next = (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  25. +              else
  26. +                     next = IKEV2_PAYLOAD_SA;
  27. +              break;
  28. +
  29. +       case (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  30. +
  31. +              if(session->local_ipv6_addresses_ptr->next)
  32. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  33. +              else
  34. +                     next = IKEV2_PAYLOAD_SA;
  35. +              break;
  36. +
  37.  #endif /* MOBIKE */
  38.  
  39.         case IKEV2_PAYLOAD_SA:
  40. @@ -1360,9 +1385,26 @@ int message_send_ike_auth_i(struct session *session)
  41.         guint32 enclen, ilen, payloadid_len = 0;
  42.         GSList *certs_for_peer;
  43.         GSList *sig_ca_items = NULL, *hash_ca_items = NULL;
  44. +#ifdef MOBIKE
  45. +       /*
  46. +        * IPv4 and IPv6 address buffers
  47. +        */
  48. +       unsigned long addr;
  49. +       char addr6[16];
  50. +
  51. +       struct network_address *addr_data;
  52. +
  53. +       GSList *lcl4ptr, *lcl6ptr;
  54. +#endif /* MOBIKE */
  55.  
  56.         LOG_FUNC_START(1);
  57.  
  58. +#ifdef MOBIKE
  59. +       session->ike_auth_exchange_counter++;
  60. +
  61. +       session->local_ipv4_addresses_ptr = session->local_ipv4_addresses;
  62. +       session->local_ipv6_addresses_ptr = session->local_ipv6_addresses;
  63. +#endif /* MOBIKE */
  64.         retval = -1;
  65.         buffer = NULL;
  66.  
  67. @@ -1597,6 +1639,33 @@ int message_send_ike_auth_i(struct session *session)
  68.                       LOG_DEBUG("Created MOBIKE_SUPPORTED notification");
  69.                       LOG_TRACE("Created NOTIFY payload len = %u", len);
  70.                       break;
  71. +
  72. +              case (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  73. +                     lcl4ptr = session->local_ipv4_addresses_ptr;
  74. +                     addr_data = (struct network_address *)(lcl4ptr->data);
  75. +                     addr = 0;
  76. +                     addr_data->netaddr;
  77. +                     /*->sin.sin_addr.s_addr;*/
  78. +
  79. +                     len = payload_notify_mobike_create(next, N_ADDITIONAL_IP4_ADDRESS,
  80. +                                          (char *)addr, (guint16)(htons(sizeof(addr))), p);
  81. +                     LOG_DEBUG("Created ADDITIONAL_IP4_ADDRESS notification");
  82. +                     LOG_TRACE("Created NOTIFY payload len = %u", len);
  83. +                     session->local_ipv4_addresses_ptr =
  84. +                                   session->local_ipv4_addresses_ptr->next;
  85. +                     break;
  86. +
  87. +              case (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  88. +                     addr6 =
  89. +                            session->local_ipv6_addresses_ptr->data->netaddr->sin6.sin6_addr.s6_addr;
  90. +
  91. +                     len = payload_notify_mobike_create(next, N_ADDITIONAL_IP6_ADDRESS,
  92. +                                          addr6, (guint16)(htons(sizeof(addr6))), p);
  93. +                     LOG_DEBUG("Created ADDITIONAL_IP6_ADDRESS notification");
  94. +                     LOG_TRACE("Created NOTIFY payload len = %u", len);
  95. +                     session->local_ipv6_addresses_ptr =
  96. +                                   session->local_ipv6_addresses_ptr->next;
  97. +                     break;
  98.  #endif /* MOBIKE */
  99.                }
  100.  
  101. @@ -1770,8 +1839,33 @@ guint32 message_ike_auth_r_payload_next(struct session *session, guint32 curr)
  102.  
  103.  #ifdef MOBIKE
  104.         case (N_MOBIKE_SUPPORTED << 8 | IKEV2_PAYLOAD_NOTIFY):
  105. -              next = IKEV2_PAYLOAD_SA;
  106. +
  107. +              if(session->local_ipv4_addresses_ptr)
  108. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  109. +              else if(session->local_ipv6_addresses_ptr)
  110. +                     next = (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  111. +              else
  112. +                     next = IKEV2_PAYLOAD_SA;
  113.                break;
  114. +
  115. +       case (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  116. +
  117. +              if(session->local_ipv4_addresses_ptr->next)
  118. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  119. +              else if(session->local_ipv6_addresses_ptr)
  120. +                     next = (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  121. +              else
  122. +                     next = IKEV2_PAYLOAD_SA;
  123. +              break;
  124. +
  125. +       case (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  126. +
  127. +              if(session->local_ipv6_addresses_ptr->next)
  128. +                     next = (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY);
  129. +              else
  130. +                     next = IKEV2_PAYLOAD_SA;
  131. +              break;
  132. +
  133.  #endif /* MOBIKE */
  134.  
  135.         case IKEV2_PAYLOAD_SA:
  136. @@ -1826,9 +1920,23 @@ int message_send_ike_auth_r(struct session *session,
  137.         gpointer payloadid = NULL;
  138.         int auth_payload_len, payloadid_len = 0;
  139.         GSList *certs_for_peer;
  140. +#ifdef MOBIKE
  141. +       /*
  142. +        * IPv4 and IPv6 address buffers
  143. +        */
  144. +       unsigned long addr;
  145. +       char addr6[16];
  146. +
  147. +       struct network_address *addr_data;
  148. +#endif /* MOBIKE */
  149.  
  150.         LOG_FUNC_START(1);
  151.  
  152. +#ifdef MOBIKE
  153. +       session->local_ipv4_addresses_ptr = session->local_ipv4_addresses;
  154. +       session->local_ipv6_addresses_ptr = session->local_ipv6_addresses;
  155. +#endif /* MOBIKE */
  156. +
  157.         /*
  158.          * Find corresponding CHILD SA structure
  159.          */
  160. @@ -2022,6 +2130,34 @@ int message_send_ike_auth_r(struct session *session,
  161.                       LOG_DEBUG("Created MOBIKE_SUPPORTED notification");
  162.                       LOG_TRACE("Created NOTIFY payload len = %u", len);
  163.                       break;
  164. +
  165. +              case (N_ADDITIONAL_IP4_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  166. +                     /* addr_data = (struct netaddr *) */
  167. +/*               *((struct network_address *)
  168. +                                   g_slist_nth_data(session->local_ipv4_addresses_ptr, 0));
  169. +                     addr = 0;
  170. +                     addr_data; */
  171. +                     /*->sin.sin_addr.s_addr;*/
  172. +
  173. +                     len = payload_notify_mobike_create(next, N_ADDITIONAL_IP4_ADDRESS,
  174. +                                          (char *)addr, (guint16)(htons(sizeof(addr))), p);
  175. +                     LOG_DEBUG("Created ADDITIONAL_IP4_ADDRESS notification");
  176. +                     LOG_TRACE("Created NOTIFY payload len = %u", len);
  177. +                     session->local_ipv4_addresses_ptr =
  178. +                                   session->local_ipv4_addresses_ptr->next;
  179. +                     break;
  180. +
  181. +              case (N_ADDITIONAL_IP6_ADDRESS << 8 | IKEV2_PAYLOAD_NOTIFY):
  182. +/*               addr6 =
  183. +                            session->local_ipv6_addresses_ptr->data->netaddr->sin6.sin6_addr.s6_addr;
  184. +*/
  185. +                     len = payload_notify_mobike_create(next, N_ADDITIONAL_IP6_ADDRESS,
  186. +                                          addr6, (guint16)(htons(sizeof(addr6))), p);
  187. +                     LOG_DEBUG("Created ADDITIONAL_IP6_ADDRESS notification");
  188. +                     LOG_TRACE("Created NOTIFY payload len = %u", len);
  189. +                     session->local_ipv6_addresses_ptr =
  190. +                                   session->local_ipv6_addresses_ptr->next;
  191. +                     break;
  192.  #endif /* MOBIKE */
  193.  
  194.                }
  195. @@ -4366,9 +4502,27 @@ gint message_parse_ike_auth_i(struct ikev2_header *hdr, gchar *p,
  196.         guint32 r1, r2;
  197.         struct cert *cert;
  198.         struct certreq *certreq;
  199. +#ifdef MOBIKE
  200. +       gboolean no_additional_addresses = FALSE;
  201. +       struct netaddr *peer_addr;
  202. +       guint16 mobike_notify_len;
  203. +#endif /* MOBIKE */
  204.  
  205.         LOG_FUNC_START(1);
  206.  
  207. +#ifdef MOBIKE
  208. +       /*
  209. +        * Create peer's address list of only one element at the moment -
  210. +        * source address found in header.
  211. +        */
  212. +       if(netaddr_get_family(msg->srcaddr) == AF_INET)
  213. +              msg->ike_auth.peer_ipv4_addresses =
  214. +                            g_slist_append(NULL, msg->srcaddr);
  215. +       else if(netaddr_get_family(msg->srcaddr) == AF_INET6)
  216. +              msg->ike_auth.peer_ipv6_addresses =
  217. +                            g_slist_append(NULL, msg->srcaddr);
  218. +#endif /* MOBIKE */
  219. +
  220.         /*
  221.          * Assume that error occured...
  222.          */
  223. @@ -4704,7 +4858,7 @@ gint message_parse_ike_auth_i(struct ikev2_header *hdr, gchar *p,
  224.                       }
  225.  
  226.  
  227. -                     LOG_DEBUG("Received N_MOBIKE_SUPPORTED notification!");
  228. +                     LOG_DEBUG("Received MOBIKE_SUPPORTED notification!");
  229.                       msg->ike_auth.peer_supports_mobike = TRUE;
  230.  
  231.                       if ((r2 = message_find_next_payload(&p, &ptype, hdr))) {
  232. @@ -4715,6 +4869,63 @@ gint message_parse_ike_auth_i(struct ikev2_header *hdr, gchar *p,
  233.  
  234.                       np = (struct payload_notify *)p;
  235.                }
  236. +
  237. +              /*
  238. +               * Process ADDITIONAL_*_ADDRESS notify payloads
  239. +               */
  240. +              while(ptype == IKEV2_PAYLOAD_NOTIFY &&
  241. +                     (ntohs(np->n_type) == N_ADDITIONAL_IP4_ADDRESS ||
  242. +                      ntohs(np->n_type) == N_ADDITIONAL_IP6_ADDRESS)) {
  243. +
  244. +                     if (payload_notify_check(p) < 0) {
  245. +                            r1 |= MSGPARSE_SEND_NOTIFY;
  246. +                            msg->notify = N_INVALID_SYNTAX;
  247. +                            goto out;
  248. +                     }
  249. +
  250. +                     payload_notify_parse(&peer_addr, &mobike_notify_len, p);
  251. +
  252. +                     if(ntohs(np->n_type) == N_ADDITIONAL_IP4_ADDRESS) {
  253. +                            LOG_DEBUG("Received ADDITIONAL_IP4_ADDRESS notification");
  254. +                            msg->ike_auth.peer_ipv4_addresses = g_slist_prepend(
  255. +                                          msg->ike_auth.peer_ipv4_addresses, peer_addr);
  256. +                     }
  257. +                     else {
  258. +                            LOG_DEBUG("Received ADDITIONAL_IP4_ADDRESS notification");
  259. +                            msg->ike_auth.peer_ipv6_addresses = g_slist_prepend(
  260. +                                          msg->ike_auth.peer_ipv6_addresses, peer_addr);
  261. +                     }
  262. +
  263. +                     if ((r2 = message_find_next_payload(&p, &ptype, hdr))) {
  264. +                            r1 |= (r2 & 0xFFFF0000);
  265. +                            msg->notify = r2 & 0xFFFF;
  266. +                            goto out;
  267. +                     }
  268. +
  269. +                     np = (struct payload_notify *)p;
  270. +              }
  271. +
  272. +              if (ptype == IKEV2_PAYLOAD_NOTIFY &&
  273. +                     ntohs(np->n_type) == N_NO_ADDITIONAL_ADDRESSES) {
  274. +
  275. +                     if (payload_notify_check(p) < 0) {
  276. +                            r1 |= MSGPARSE_SEND_NOTIFY;
  277. +                            msg->notify = N_INVALID_SYNTAX;
  278. +                            goto out;
  279. +                     }
  280. +
  281. +                     no_additional_addresses = TRUE;
  282. +
  283. +                     LOG_DEBUG("Received NO_ADDITIONAL_ADDRESSES notification!");
  284. +
  285. +                     if ((r2 = message_find_next_payload(&p, &ptype, hdr))) {
  286. +                            r1 |= (r2 & 0xFFFF0000);
  287. +                            msg->notify = r2 & 0xFFFF;
  288. +                            goto out;
  289. +                     }
  290. +
  291. +                     np = (struct payload_notify *)p;
  292. +              }
  293.  #endif /* MOBIKE */
  294.  
  295.                if (ptype == IKEV2_PAYLOAD_SA) {
  296. @@ -4807,6 +5018,25 @@ gint message_parse_ike_auth_i(struct ikev2_header *hdr, gchar *p,
  297.         }
  298.  
  299.         /*
  300. +        * Check if we received N_NO_ADDITIONAL_ADDRESSES and if so,
  301. +        * assert header source address is the only one, hence there was
  302. +        * no ADDITIONAL_*_ADDRESS notify payload.
  303. +        */
  304. +#ifdef MOBIKE
  305. +       if(no_additional_addresses == TRUE)
  306. +              if((msg->ike_auth.peer_ipv4_addresses &&
  307. +                     msg->ike_auth.peer_ipv4_addresses->next) ||
  308. +                 (msg->ike_auth.peer_ipv6_addresses &&
  309. +                     msg->ike_auth.peer_ipv6_addresses->next)) {
  310. +                     LOG_ERROR("Received notify payload for additional address as"
  311. +                                     "well as NO_ADDITIONAL_ADDRESSES");
  312. +                     r1 |= MSGPARSE_SEND_NOTIFY;
  313. +                     msg->notify = N_INVALID_SYNTAX;
  314. +                     goto out;
  315. +              }
  316. +#endif MOBIKE
  317. +
  318. +       /*
  319.          * No error occured...
  320.          */
  321.         r1 = 0;
  322. @@ -4896,9 +5126,27 @@ gint message_parse_ike_auth_r(struct ikev2_header *hdr, gchar *p,
  323.         guint32 r1, r2;
  324.         struct cert *cert;
  325.         gboolean error;
  326. +#ifdef MOBIKE
  327. +       gboolean no_additional_addresses = FALSE;
  328. +       struct netaddr *peer_addr;
  329. +       guint16 mobike_notify_len;
  330. +#endif /* MOBIKE */
  331.  
  332.         LOG_FUNC_START(1);
  333.  
  334. +#ifdef MOBIKE
  335. +       /*
  336. +        * Create peer's address list of only one element at the moment -
  337. +        * source address found in header.
  338. +        */
  339. +       if(netaddr_get_family(msg->srcaddr) == AF_INET)
  340. +              msg->ike_auth.peer_ipv4_addresses =
  341. +                            g_slist_append(NULL, msg->srcaddr);
  342. +       else if(netaddr_get_family(msg->srcaddr) == AF_INET6)
  343. +              msg->ike_auth.peer_ipv6_addresses =
  344. +                            g_slist_append(NULL, msg->srcaddr);
  345. +#endif /* MOBIKE */
  346. +
  347.         /*
  348.          * Assume that error occured...
  349.          */
  350. @@ -5126,6 +5374,23 @@ gint message_parse_ike_auth_r(struct ikev2_header *hdr, gchar *p,
  351.                       case N_MOBIKE_SUPPORTED:
  352.                              msg->ike_auth.peer_supports_mobike = TRUE;
  353.                              break;
  354. +
  355. +                     case N_ADDITIONAL_IP4_ADDRESS:
  356. +                            payload_notify_parse(&peer_addr, &mobike_notify_len, p);
  357. +                            msg->ike_auth.peer_ipv4_addresses = g_slist_prepend(
  358. +                                          msg->ike_auth.peer_ipv4_addresses, peer_addr);
  359. +                            break;
  360. +
  361. +                     case N_ADDITIONAL_IP6_ADDRESS:
  362. +                            payload_notify_parse(&peer_addr, &mobike_notify_len, p);
  363. +                            msg->ike_auth.peer_ipv6_addresses = g_slist_prepend(
  364. +                                          msg->ike_auth.peer_ipv6_addresses, peer_addr);
  365. +                            break;
  366. +
  367. +                     case N_NO_ADDITIONAL_ADDRESSES:
  368. +                            no_additional_addresses = TRUE;
  369. +                            break;
  370. +
  371.  #endif /*MOBIKE */
  372.  
  373.                       default:
  374. @@ -5252,6 +5517,25 @@ out_finish:
  375.         }
  376.  
  377.         /*
  378. +        * Check if we received N_NO_ADDITIONAL_ADDRESSES and if so,
  379. +        * assert header source address is the only one, hence there was
  380. +        * no ADDITIONAL_*_ADDRESS notify payload.
  381. +        */
  382. +#ifdef MOBIKE
  383. +       if(no_additional_addresses == TRUE)
  384. +              if((msg->ike_auth.peer_ipv4_addresses &&
  385. +                     msg->ike_auth.peer_ipv4_addresses->next) ||
  386. +                 (msg->ike_auth.peer_ipv6_addresses &&
  387. +                     msg->ike_auth.peer_ipv6_addresses->next)) {
  388. +                     LOG_ERROR("Received notify payload for additional address as"
  389. +                                     "well as NO_ADDITIONAL_ADDRESSES");
  390. +                     r1 |= MSGPARSE_SEND_NOTIFY;
  391. +                     msg->notify = N_INVALID_SYNTAX;
  392. +                     goto out;
  393. +              }
  394. +#endif MOBIKE
  395. +
  396. +       /*
  397.          * No error occured...
  398.          */
  399.         r1 = 0;
  400. diff --git src/message_msg.h src/message_msg.h
  401. index 35912bd..b6231a4 100644
  402. --- src/message_msg.h
  403. +++ src/message_msg.h
  404. @@ -133,7 +133,7 @@ struct ike_sa_init {
  405.  struct ike_auth {
  406.  
  407.         /**
  408. -        * Does initiator requested transport mode?
  409. +        * Has initiator requested transport mode?
  410.          */
  411.         gint transport_mode:1;
  412.  
  413. @@ -245,6 +245,14 @@ struct ike_auth {
  414.          */
  415.         GSList *cert_list;
  416.         GSList *certreq_list;
  417. +
  418. +       /**
  419. +        * Lists of remote peer's IPv4 and IPv6 addresses
  420. +        */
  421. +#ifdef MOBIKE
  422. +       GSList *peer_ipv4_addresses;
  423. +       GSList *peer_ipv6_addresses;
  424. +#endif /* MOBIKE */
  425.  };
  426.  
  427.  /**
  428. diff --git src/network.c src/network.c
  429. index 342b5de..5069923 100644
  430. --- src/network.c
  431. +++ src/network.c
  432. @@ -1676,3 +1676,182 @@ out:
  433.         return retval;
  434.  }
  435.  
  436. +/**
  437. +  * Compares two interfaces by name and index.
  438. +  *
  439. +  * @param ni1  First interface to compare
  440. +  * @param ni2  Second interface to compare
  441. +  *
  442. +  * \return 1    If two interfaces differ by name or index or both
  443. +  *        0         Otherwise
  444. +  */
  445. +int network_compare_interfaces(struct netif *ni1, struct netif *ni2) {
  446. +
  447. +       LOG_FUNC_START(1);
  448. +
  449. +       if(strcmp(netif_get_name(ni1), netif_get_name(ni2)))
  450. +              return 1;
  451. +
  452. +       LOG_FUNC_END(1);
  453. +
  454. +       return ni1->if_index == ni2->if_index ? 0 : 1;
  455. +}
  456. +
  457. +/**
  458. + * Compares interfaces in two network_data structures.
  459. + *
  460. + * @param data1                First network_data data which interfaces are to be compared
  461. + * @param data2                Second network_data data to be compared to data1 interfaces
  462. + *
  463. + * \return     1    If interfaces in data1 and data2 differ
  464. + *          0    otherwise
  465. + */
  466. +int network_compare_interface_lists(struct network_data *data1,
  467. +                                                               struct network_data *data2) {
  468. +
  469. +       int retval;
  470. +       GSList *list1, *list2;
  471. +
  472. +       LOG_FUNC_START(1);
  473. +
  474. +       retval = 0;
  475. +
  476. +       list1 = data1->interfaces;
  477. +       list2 = data2->interfaces;
  478. +
  479. +       /*
  480. +        * Iterate through both interface lists one interface at a time
  481. +        */
  482. +       while(list1 && list2 && !retval) {
  483. +
  484. +              if(network_compare_interfaces(list1->data, list2->data))
  485. +                     retval = 1;
  486. +
  487. +              list1 = list1->next;
  488. +              list2 = list2->next;
  489. +       }
  490. +
  491. +       if(list1 || list2)
  492. +              retval = 1;
  493. +
  494. +       LOG_FUNC_END(1);
  495. +
  496. +       return retval;
  497. +}
  498. +
  499. +
  500. +/**
  501. + * Compares addresses in two network_data structures.
  502. + *
  503. + * @param data1                First network_data data which addresses are to be compared
  504. + * @param data2                Second network_data data to be compared to data1 addresses
  505. + *
  506. + * \return     1    If addresses in data1 and data2 differ
  507. + *          0    otherwise
  508. + */
  509. +int network_compare_address_lists(struct network_data *data1,
  510. +                                                                             struct network_data *data2) {
  511. +
  512. +       int retval;
  513. +       GSList *list1, *list2;
  514. +       struct network_address *a1, *a2;
  515. +
  516. +       LOG_FUNC_START(1);
  517. +
  518. +       retval = 0;
  519. +
  520. +       list1 = data1->addresses;
  521. +       list2 = data2->addresses;
  522. +
  523. +       /*
  524. +        * Iterate through both address lists one address at a time
  525. +        */
  526. +       while(list1 && list2 && !retval) {
  527. +
  528. +              a1 = (struct network_addresss *)(list1->data);
  529. +              a2 = (struct network_addresss *)(list2->data);
  530. +
  531. +              if(netaddr_same_family(a1->netaddr, a2->netaddr)) {
  532. +                     if(netaddr_cmp_ip2ip(a1->netaddr, a2->netaddr))
  533. +                            retval = 1;
  534. +              }
  535. +              else
  536. +                     retval = 1;
  537. +
  538. +
  539. +              list1 = list1->next;
  540. +              list2 = list2->next;
  541. +       }
  542. +
  543. +       if(list1 || list2)
  544. +              retval = 1;
  545. +
  546. +       LOG_FUNC_END(1);
  547. +
  548. +       return retval;
  549. +}
  550. +
  551. +/**
  552. +  * Checks for changes in network interfaces and addresses.
  553. +  */
  554. +void network_check_links() {
  555. +
  556. +       struct network_data *network_data_new;
  557. +       gboolean queue_message;
  558. +
  559. +       LOG_FUNC_START(1);
  560. +
  561. +       network_data_new = g_malloc0(sizeof(struct network_data));
  562. +       queue_message = FALSE;
  563. +
  564. +       /*
  565. +        * TODO: what does context represent?
  566. +        */
  567. +       network_data_new->context = NULL;
  568. +
  569. +       /*
  570. +        * Lock interfaces and addresses in network_data for reading
  571. +        */
  572. +       g_static_rw_lock_reader_lock(&network_data->interfaces_lock);
  573. +       g_static_rw_lock_reader_lock(&network_data->addresses_lock);
  574. +
  575. +       if (network_enumerate_interfaces(network_data_new) < 0)
  576. +              goto out;
  577. +
  578. +       /*
  579. +        * Search for IPv4 addresses
  580. +        */
  581. +       if (network_enumerate_addresses(network_data_new, AF_INET) < 0)
  582. +              goto out;
  583. +
  584. +       /*
  585. +       * Search for IPv6 addresses
  586. +       */
  587. +       if (network_enumerate_addresses(network_data_new, AF_INET6) < 0)
  588. +              goto out;
  589. +
  590. +       /*
  591. +       * Compare interfaces and addresses
  592. +       */
  593. +       if(network_compare_interface_lists(network_data_new, network_data))
  594. +              queue_message = TRUE;
  595. +       else if(network_compare_address_lists(network_data_new, network_data))
  596. +              queue_message = TRUE;
  597. +
  598. +       /*
  599. +        * Send message to some queue if interfaces or addresses have changed
  600. +        */
  601. +       if(queue_message == TRUE) {
  602. +              /*
  603. +               * Tu treba poslati neku poruku (treba ju oblikovati) u neki red.
  604. +               * Netko po primitku te poruke treba izbrisati postojei automat
  605. +               * stanja parova IP adresa
  606. +               */
  607. +       }
  608. +
  609. +out:
  610. +       g_static_rw_lock_reader_unlock(&network_data->interfaces_lock);
  611. +       g_static_rw_lock_reader_unlock(&network_data->addresses_lock);
  612. +
  613. +       LOG_FUNC_END(1);
  614. +}
  615. diff --git src/network.h src/network.h
  616. index f928577..9a6d519 100644
  617. --- src/network.h
  618. +++ src/network.h
  619. @@ -181,8 +181,8 @@ struct network_data {
  620.          *
  621.          * TODO: This has to be converted into hash indexed by interface name
  622.          */
  623. +       GStaticRWLock interfaces_lock;
  624.         GSList *interfaces;
  625. -
  626.  };
  627.  
  628.  #else /* __NETWORK_C */
  629. diff --git src/payload.c src/payload.c
  630. index 1cd2f20..79e274f 100644
  631. --- src/payload.c
  632. +++ src/payload.c
  633. @@ -1157,6 +1157,10 @@ gint32 payload_notify_parse(void **data, guint16 *notify_data_len, char *p)
  634.         p += sizeof(struct payload_notify);
  635.         ntype = ntohs(np->n_type);
  636.  
  637. +       /*
  638. +        * Be careful about this check because MOBIKE introduces
  639. +        * new notify payloads with ntype > 16395
  640. +        */
  641.         if (ntype == 0
  642.                || (ntype > 39 && ntype < 16384)
  643.                || (ntype > 16395)) {
  644. @@ -1227,6 +1231,19 @@ gint32 payload_notify_parse(void **data, guint16 *notify_data_len, char *p)
  645.                *((guint32 *)(*data)) = *((guint32 *)p);
  646.                break;
  647.  
  648. +#ifdef MOBIKE
  649. +       case N_MOBIKE_SUPPORTED:
  650. +       case NO_ADDITIONAL_ADDRESSES:
  651. +              break;
  652. +
  653. +       case N_ADDITIONAL_IP4_ADDRESS:
  654. +       case N_ADDITIONAL_IP4_ADDRESS:
  655. +              *data = p;
  656. +              *notify_data_len = ntohs(np->length) -
  657. +                                             sizeof(struct payload_notify);
  658. +              break;
  659. +#endif /* MOBIKE */
  660. +
  661.         default:
  662.                printf ("ERROR: Unknown/unsupported notify (0x%x) in "
  663.                       "%s:%s:%d\n",
  664. diff --git src/session.c src/session.c
  665. index 9569983..7c0aae9 100644
  666. --- src/session.c
  667. +++ src/session.c
  668. @@ -123,6 +123,14 @@ struct session *session_new(void)
  669.  
  670.         session->embedded_sm_msg = NULL;
  671.  
  672. +       session->peer_addresses = NULL;
  673. +
  674. +#ifdef MOBIKE
  675. +       ike_auth_exchange_counter = 0;
  676. +
  677. +       session_local_addresses_init(session);
  678. +#endif /* MOBIKE */
  679. +
  680.         LOG_FUNC_END(2);
  681.  
  682.         return session;
  683. @@ -251,6 +259,7 @@ gboolean session_free(struct session *session)
  684.                if (session->sent_resp_mux)
  685.                       g_mutex_free(session->sent_resp_mux);
  686.  
  687. +              if (session)
  688.                g_free (session);
  689.  
  690.         } else {
  691. @@ -1093,3 +1102,47 @@ gboolean session_use_radius(struct session *session)
  692.  #endif
  693.                return FALSE;
  694.  }
  695. +
  696. +#ifdef MOBIKE
  697. +GSList *session_add_address(GSList *list,
  698. +                                                         struct netaddr *addr) {
  699. +
  700. +       GSList *new_address = NULL;
  701. +
  702. +       LOG_FUNC_START(1);
  703. +
  704. +       new_address = g_slist_prepend(new_address, addr);
  705. +       new_address = g_slist_prepend(list, new_address);
  706. +
  707. +       LOG_FUNC_END(1);
  708. +
  709. +       return new_address;
  710. +}
  711. +
  712. +void session_local_addresses_init(struct session *session) {
  713. +
  714. +       GSList *network_data_iterator;
  715. +       struct network_address *addr;
  716. +
  717. +       LOG_FUNC_START(1);
  718. +
  719. +       network_data_iterator = network_data->addresses;
  720. +
  721. +       session->local_ipv4_addresses = NULL;
  722. +       session->local_ipv6_addresses = NULL;
  723. +
  724. +       while(network_data_iterator) {
  725. +              addr = (struct network_address *)network_data_iterator->data;
  726. +              if(addr->netaddr->sin->sa.sa_family == AF_INET)
  727. +                     session->local_ipv4_addresses =
  728. +                                   session_add_address(session->local_ipv4_addresses, addr);
  729. +              else
  730. +                     session->local_ipv6_addresses =
  731. +                                   session_add_address(session->local_ipv6_addresses, addr);
  732. +
  733. +              network_data_iterator = network_data_iterator->next;
  734. +       }
  735. +
  736. +       LOG_FUNC_END(1);
  737. +}
  738. +#endif /* MOBIKE */
  739. diff --git src/session.h src/session.h
  740. index ed6202e..0747754 100644
  741. --- src/session.h
  742. +++ src/session.h
  743. @@ -92,6 +92,41 @@
  744.  #define MAX_HALF_OPENED_SESSIONS       2
  745.  
  746.  /**
  747. + * Structure for holding local and remote addresses making pair of addresses
  748. + * in a IP addresses state machine.
  749. + */
  750. +struct pair_of_addresses {
  751. +       /**
  752. +        * One of initiator's and one of responder's addresses.
  753. +        *
  754. +        * Those addresses also hold ports!
  755. +        */
  756. +       struct netaddr *i_addr, *r_addr;
  757. +
  758. +       /**
  759. +        * State of address pair in IP Address Pair State Machine.
  760. +        *
  761. +        * Possible states are:
  762. +        *
  763. +        * ADDRESS_PAIR_INVALID                        0
  764. +        * ADDRESS_PAIR_VALID      1
  765. +        * ADDRESS_PAIR_NEGOTIATING        2
  766. +        * ADDRESS_PAIR_ACTIVE   3
  767. +        * ADDRESS_PAIR_TRANSITING          4
  768. +        * ADDRESS_PAIR_INEXISTING          5
  769. +        *
  770. +        * Default state is ADDRESS_PAIR_INVALID.
  771. +        */
  772. +       guint8 state;
  773. +
  774. +       /**
  775. +        * These are the time fields for return routability check timeout.
  776. +        */
  777. +       GTimeVal rrc_timeout;
  778. +       timeout_t *to;
  779. +};
  780. +
  781. +/**
  782.   * In the following structure all the fields marked as transient are
  783.   * valid only throughout some particular lifetime of IKE SA, e.g.
  784.   * during cration, rekeying, reautentification, etc.
  785. @@ -288,6 +323,24 @@ struct session {
  786.          */
  787.         struct netaddr *i_addr, *r_addr;
  788.  
  789. +       /**
  790. +        * List of remote peer's IPv4 and IPv6 addresses
  791. +        */
  792. +       GSList *peer_ipv4_addresses;
  793. +       GSList *peer_ipv6_addresses;
  794. +
  795. +       /**
  796. +        * List of pair of addresses, their states and timeouts in
  797. +        * IP address state machine in MOBIKE.
  798. +        * One pair consists of initiator's address and of respodnder's address.
  799. +        */
  800. +       GSList *pair_of_addresses_list;
  801. +       /**
  802. +        * Pointer to active address from pair_of_addresses_list list
  803. +        * TODO: This variable should replace i_addr and r_addr variables.
  804. +        */
  805. +       GSList *active_address_pair;
  806. +
  807.  #ifdef SUPPLICANT
  808.         /**
  809.          * Pointer to a structure with EAP states
  810. @@ -452,6 +505,35 @@ struct session {
  811.          */
  812.  #ifdef MOBIKE
  813.         gboolean mobike_supported;
  814. +
  815. +       /**
  816. +        * Counter for IKE AUTH exchanges. It serves for determining if
  817. +        * particular exchange contains SA payload, hence 1st IKE AUTH
  818. +        * exchange.
  819. +        */
  820. +       guint8 ike_auth_exchange_counter;
  821. +
  822. +       /*
  823. +        * Lists of local IP addresses initialized in network_init() function.
  824. +        * Temporary pointers are needed for ADDITIONAL_*_ADDRESS notify
  825. +        * payloads in IKE AUTH and INFORMATIONAL exchanges.
  826. +        */
  827. +       GSList *local_ipv4_addresses;
  828. +       GSList *local_ipv6_addresses;
  829. +
  830. +       GSList *local_ipv4_addresses_ptr;
  831. +       GSList *local_ipv6_addresses_ptr;
  832. +
  833. +       /**
  834. +        * FIXME
  835. +        * If we are to switch to MOBIKE port (4500) to send IKE_AUTH and
  836. +        * it turns out that remote peer does not support MOBIKE for this
  837. +        * connection, we need to switch to ports set previously. That
  838. +        * could be IKEV2_PORT_NATT (4500), default port (500) as well as
  839. +        * any other set by any party
  840. +        */
  841. +        guint16 previous_port_i;
  842. +        guint16 previous_port_r;
  843.  #endif /* MOBIKE */
  844.  
  845.  #ifdef CFG_CLIENT
  846. @@ -537,19 +619,6 @@ struct session {
  847.          * pass). This complicates code with many #ifdef's and if's.
  848.          */
  849.         union sm_msg *embedded_sm_msg;
  850. -
  851. -       /**
  852. -        * FIXME
  853. -        * If we are to switch to MOBIKE port (4500) to send IKE_AUTH and
  854. -        * it turns out that remote peer does not support MOBIKE for this
  855. -        * connection, we need to switch to ports set previously. That
  856. -        * could be IKEV2_PORT_NATT (4500), default port (500) as well as
  857. -        * any other set by any party
  858. -        */
  859. -#ifdef MOBIKE
  860. -        guint16 previous_port_i;
  861. -        guint16 previous_port_r;
  862. -#endif /* MOBIKE */
  863.  };
  864.  
  865.  /*******************************************************************************
  866. @@ -661,6 +730,8 @@ struct sad_item *session_sad_item_find_by_msg_id(struct session *, guint32);
  867.  int session_crypto_material(struct session *);
  868.  
  869.  gboolean session_use_radius(struct session *);
  870. +
  871. +GSList *session_add_peer_address(struct session *, struct netaddr *);
  872.  /*******************************************************************************
  873.   * DEBUG METHODS
  874.   ******************************************************************************/
  875. diff --git src/sm.c src/sm.c
  876. index 25df5f2..368a00d 100644
  877. --- src/sm.c
  878. +++ src/sm.c
  879. @@ -4420,7 +4420,7 @@ int sm_ike_i_thread(struct session *session, union sm_msg *sm_msg)
  880.                }
  881.  
  882.                /*
  883. -               * Check if we received notify INVALID_SYNTAX. In that case
  884. +               * Check if we received notify NO_PROPOSAL_CHOSEN. In that case
  885.                 * terminate IKE SA..
  886.                 */
  887.                if (sm_msg->message_msg.ike_sa_init.no_proposal_chosen) {

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

fantasy-obligation
fantasy-obligation