summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl/ipoe/dhcpv4.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/ctrl/ipoe/dhcpv4.c')
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index 6d0d1c9c..ccad3182 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.c
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.c
@@ -22,6 +22,8 @@
#include "memdebug.h"
#include "ap_session.h"
#include "ipdb.h"
+#include "radius.h"
+#include "dhcp_attr_defs.h"
#include "dhcpv4.h"
@@ -1126,6 +1128,46 @@ void dhcpv4_reserve_ip(struct dhcpv4_serv *serv, uint32_t ip)
pthread_mutex_unlock(&serv->range->lock);
}
+struct dhcpv4_packet *dhcpv4_clone_radius(struct rad_packet_t *rad)
+{
+ struct dhcpv4_packet *pkt = dhcpv4_packet_alloc();
+ uint8_t *ptr = pkt->data, *endptr = ptr + BUF_SIZE;
+ struct dhcpv4_option *opt;
+ struct rad_attr_t *attr;
+
+ if (!pkt)
+ return NULL;
+
+ pkt->refs = 1;
+
+ list_for_each_entry(attr, &rad->attrs, entry) {
+ if (attr->vendor && attr->vendor->id == VENDOR_DHCP && attr->attr->id < 256) {
+ if (ptr + attr->len >= endptr)
+ goto out;
+
+ opt = mempool_alloc(opt_pool);
+ if (!opt) {
+ log_emerg("out of memory\n");
+ goto out;
+ }
+ memset(opt, 0, sizeof(*opt));
+ opt->type = attr->attr->id;
+ opt->len = attr->len;
+ opt->data = ptr;
+ memcpy(ptr, attr->raw, attr->len);
+ ptr += attr->len;
+
+ list_add_tail(&opt->entry, &pkt->options);
+ }
+ }
+
+ return pkt;
+
+out:
+ dhcpv4_packet_free(pkt);
+ return NULL;
+}
+
static void load_config()
{
const char *opt;