Revision acb04cfd sysdep/linux/netlink.c

View differences:

sysdep/linux/netlink.c
239 239
    return 1;
240 240
}
241 241

  
242
static inline ip4_addr rta_get_u32(struct rtattr *a)
243
{ return *(u32 *) RTA_DATA(a); }
244

  
245
static inline ip4_addr rta_get_ip4(struct rtattr *a)
246
{ return ip4_ntoh(*(ip4_addr *) RTA_DATA(a)); }
247

  
248
static inline ip6_addr rta_get_ip6(struct rtattr *a)
249
{ return ip6_ntoh(*(ip6_addr *) RTA_DATA(a)); }
250

  
251

  
242 252
struct rtattr *
243 253
nl_add_attr(struct nlmsghdr *h, uint bufsize, uint code, const void *data, uint dlen)
244 254
{
......
420 430
      return -1;
421 431

  
422 432
    metrics[0] |= 1 << a->rta_type;
423
    metrics[a->rta_type] = *(u32 *)RTA_DATA(a);
433
    metrics[a->rta_type] = rta_get_u32(a);
424 434
  }
425 435

  
426 436
  if (len > 0)
......
456 466
      return;
457 467
    }
458 468
  name = RTA_DATA(a[IFLA_IFNAME]);
459
  memcpy(&mtu, RTA_DATA(a[IFLA_MTU]), sizeof(u32));
469
  mtu = rta_get_u32(a[IFLA_MTU]);
460 470

  
461 471
  ifi = if_find_by_index(i->ifi_index);
462 472
  if (!new)
......
831 841
    }
832 842

  
833 843
  if (a[RTA_OIF])
834
    memcpy(&oif, RTA_DATA(a[RTA_OIF]), sizeof(oif));
844
    oif = rta_get_u32(a[RTA_OIF]);
835 845

  
836 846
  p = nl_table_map[i->rtm_table];	/* Do we know this table? */
837 847
  DBG("KRT: Got %I/%d, type=%d, oif=%d, table=%d, prid=%d, proto=%s\n", dst, i->rtm_dst_len, i->rtm_type, oif, i->rtm_table, i->rtm_protocol, p ? p->p.name : "(none)");
......
965 975
  e->u.krt.src = src;
966 976
  e->u.krt.proto = i->rtm_protocol;
967 977
  e->u.krt.type = i->rtm_type;
978
  e->u.krt.metric = 0;
968 979

  
969 980
  if (a[RTA_PRIORITY])
970
    memcpy(&e->u.krt.metric, RTA_DATA(a[RTA_PRIORITY]), sizeof(e->u.krt.metric));
971
  else
972
    e->u.krt.metric = 0;
981
    e->u.krt.metric = rta_get_u32(a[RTA_PRIORITY]);
973 982

  
974 983
  if (a[RTA_PREFSRC])
975 984
    {
......
1000 1009
      ea->attrs[0].id = EA_KRT_REALM;
1001 1010
      ea->attrs[0].flags = 0;
1002 1011
      ea->attrs[0].type = EAF_TYPE_INT;
1003
      memcpy(&ea->attrs[0].u.data, RTA_DATA(a[RTA_FLOW]), 4);
1012
      ea->attrs[0].u.data = rta_get_u32(a[RTA_FLOW]);
1004 1013
    }
1005 1014

  
1006 1015
  if (a[RTA_METRICS])

Also available in: Unified diff