X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-network%2Fsd-pppoe.c;h=e142dec66dab24803bc94683f18149f71eee3f16;hb=6357ac664c9ce8ae5b83bdb98011da24185e4efa;hp=17b2d6dab68f7b0e3d52876764fc6ddb84309fac;hpb=cda391c3f9c85578f4a4fe81d4aeb785a785000a;p=elogind.git diff --git a/src/libsystemd-network/sd-pppoe.c b/src/libsystemd-network/sd-pppoe.c index 17b2d6dab..e142dec66 100644 --- a/src/libsystemd-network/sd-pppoe.c +++ b/src/libsystemd-network/sd-pppoe.c @@ -22,6 +22,7 @@ /* See RFC 2516 */ #include +#include #include #include #include @@ -99,19 +100,13 @@ struct sd_pppoe { be16toh((header)->length) #define PPPOE_PACKET_TAIL(packet) \ - (struct pppoe_tag *)((uint8_t*)(packet) + sizeof(struct pppoe_hdr) + PPPOE_PACKET_LENGTH(packet)) + (struct pppoe_tag*)((uint8_t*)(packet) + sizeof(struct pppoe_hdr) + PPPOE_PACKET_LENGTH(packet)) -#define PPPOE_TAG_LENGTH(tag) \ - unaligned_read_be16(&(tag)->tag_len) +#define PPPOE_TAG_LENGTH(tag) \ + be16toh((tag)->tag_len) -#define PPPOE_TAG_TYPE(tag) \ - htobe16(unaligned_read_be16(&(tag)->tag_type)) - -#define PPPOE_TAG_SET_LENGTH(tag, len) \ - unaligned_write_be16(&(tag)->tag_len, len) - -#define PPPOE_TAG_SET_TYPE(tag, len) \ - unaligned_write_be16(&(tag)->tag_type, be16toh(len)) +#define PPPOE_TAG_TYPE(tag) \ + (tag)->tag_type #define PPPOE_TAG_NEXT(tag) \ (struct pppoe_tag *)((uint8_t *)(tag) + sizeof(struct pppoe_tag) + PPPOE_TAG_LENGTH(tag)) @@ -216,6 +211,8 @@ sd_pppoe *sd_pppoe_ref(sd_pppoe *ppp) { sd_pppoe *sd_pppoe_unref(sd_pppoe *ppp) { if (ppp && REFCNT_DEC(ppp->n_ref) <= 0) { pppoe_tags_clear(&ppp->tags); + free(ppp->ifname); + free(ppp->service_name); sd_pppoe_stop(ppp); sd_pppoe_detach_event(ppp); @@ -275,8 +272,8 @@ static void pppoe_tag_append(struct pppoe_hdr *packet, size_t packet_size, be16_ tag = PPPOE_PACKET_TAIL(packet); - PPPOE_TAG_SET_LENGTH(tag, tag_len); - PPPOE_TAG_SET_TYPE(tag, tag_type); + tag->tag_len = htobe16(tag_len); + tag->tag_type = tag_type; if (tag_data) memcpy(tag->tag_data, tag_data, tag_len); @@ -695,8 +692,7 @@ static int pppoe_handle_message(sd_pppoe *ppp, struct pppoe_hdr *packet, struct return 0; } -static int pppoe_receive_message(sd_event_source *s, int fd, - uint32_t revents, void *userdata) { +static int pppoe_receive_message(sd_event_source *s, int fd, uint32_t revents, void *userdata) { sd_pppoe *ppp = userdata; _cleanup_free_ struct pppoe_hdr *packet = NULL; union sockaddr_union link = {}; @@ -718,11 +714,9 @@ static int pppoe_receive_message(sd_event_source *s, int fd, if (!packet) return -ENOMEM; - len = recvfrom(fd, packet, buflen, 0, - &link.sa, &addrlen); + len = recvfrom(fd, packet, buflen, 0, &link.sa, &addrlen); if (len < 0) { - log_warning("PPPoE: colud not receive message from raw socket: %s", - strerror(-r)); + log_warning("PPPoE: could not receive message from raw socket: %s", strerror(-r)); return 0; } else if ((size_t)len < sizeof(struct pppoe_hdr)) return 0;