[hipl-dev] Re: [Branch ~hipl-core/hipl/mobility-fixes] Rev 5174: moved locator construction to update module

  • From: Diego Biurrun <diego@xxxxxxxxxx>
  • To: hipl-dev@xxxxxxxxxxxxx
  • Date: Fri, 19 Nov 2010 20:29:58 +0100

On Fri, Nov 19, 2010 at 05:25:46PM +0000, noreply@xxxxxxxxxxxxx wrote:
> ------------------------------------------------------------
> revno: 5174
> committer: Rene Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
> branch nick: mobility-fixes
> timestamp: Fri 2010-11-19 18:23:54 +0100
> message:
>   moved locator construction to update module
> modified:
>   lib/core/builder.c
>   lib/core/builder.h
>   modules/update/hipd/update_builder.c
>   modules/update/hipd/update_builder.h
>   modules/update/hipd/update_legacy.c
> 
> 
> --- lib/core/builder.c        2010-11-19 17:10:37 +0000
> +++ lib/core/builder.c        2010-11-19 17:23:54 +0000
> @@ -1058,7 +1058,7 @@
>   * @param contents_size size of the contents after the TLV header
>   *                 (in host byte order)
>   */
> -static void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
> +void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
>                                         hip_tlv_len_t tlv_size,
>                                         hip_tlv_len_t contents_size)

Indentation is now off.

> --- lib/core/builder.h        2010-11-19 17:10:37 +0000
> +++ lib/core/builder.h        2010-11-19 17:23:54 +0000
> @@ -213,6 +210,9 @@
>  hip_transform_suite_t hip_get_param_transform_suite_id(const void *);
>  hip_tlv_type_t hip_get_param_type(const void *);
>  void hip_set_param_type(struct hip_tlv_common *tlv_generic, hip_tlv_type_t 
> type);
> +void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
> +                                       hip_tlv_len_t tlv_size,
> +                                       hip_tlv_len_t contents_size);

Indentation is off.

> --- modules/update/hipd/update_builder.c      2010-11-19 17:07:10 +0000
> +++ modules/update/hipd/update_builder.c      2010-11-19 17:23:54 +0000
> @@ -75,3 +78,37 @@
> +int hip_build_param_locator(struct hip_common *msg,
> +                            struct hip_locator_info_addr_item *addrs,
> +                            int addr_count)
> +{
> +    int err                          = 0;
> +    struct hip_locator *locator_info = NULL;
> +    int addrs_len = addr_count * (sizeof(struct hip_locator_info_addr_item));
> +
> +    HIP_IFE(!(locator_info = malloc(sizeof(struct hip_locator) + 
> addrs_len)), -1);
> +
> +    hip_set_param_type((struct hip_tlv_common *) locator_info, 
> HIP_PARAM_LOCATOR);
> +
> +    hip_calc_generic_param_len((struct hip_tlv_common *) locator_info,
> +                               sizeof(struct hip_locator),
> +                               addrs_len);

Why not make locator_info the right type from the start instead of
casting it?

> +    memcpy(locator_info + 1, addrs, addrs_len);
> +    HIP_IFE(hip_build_param(msg, locator_info), -1);
> +
> +out_err:
> +    if (locator_info) {
> +        free(locator_info);

Pointless NULL check before free().

Diego

Other related posts: