2016-10-14 14:47:46 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <openssl/engine.h>
|
|
|
|
#include <openssl/hmac.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/logging.h>
|
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <osmocom/core/socket.h>
|
2016-10-18 14:11:22 +00:00
|
|
|
#include <osmocom/core/fsm.h>
|
2016-10-14 14:47:46 +00:00
|
|
|
|
|
|
|
#include "l2tp_protocol.h"
|
|
|
|
#include "l2tpd.h"
|
2016-10-18 14:11:22 +00:00
|
|
|
#include "l2tpd_data.h"
|
2016-10-17 00:11:32 +00:00
|
|
|
#include "l2tpd_fsm.h"
|
2016-10-24 03:14:56 +00:00
|
|
|
#include "l2tpd_packet.h"
|
2016-10-14 14:47:46 +00:00
|
|
|
|
2016-10-18 14:11:22 +00:00
|
|
|
struct l2tpd_instance *l2i;
|
|
|
|
/* FIXME: global static instance */
|
|
|
|
|
2016-10-14 14:47:46 +00:00
|
|
|
static int l2tp_ip_read_cb(struct osmo_fd *ofd, unsigned int what)
|
|
|
|
{
|
|
|
|
struct msgb *msg = l2tp_msgb_alloc();
|
2016-10-23 14:29:56 +00:00
|
|
|
struct sockaddr ss;
|
|
|
|
socklen_t ss_len = sizeof(ss);
|
2016-10-14 14:47:46 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* actually read the message from the raw IP socket */
|
2016-10-23 22:50:09 +00:00
|
|
|
rc = recvfrom(ofd->fd, msg->data, msg->data_len, 0,
|
2016-10-23 14:29:56 +00:00
|
|
|
(struct sockaddr *) &ss, &ss_len);
|
2016-10-14 14:47:46 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
msgb_put(msg, rc);
|
2016-10-23 22:50:09 +00:00
|
|
|
msg->l1h = msg->data; /* l1h = ip header */
|
|
|
|
|
|
|
|
msgb_pull(msg, 20); /* IPv4 header. FIXME: Should depend on the family */
|
|
|
|
msg->l2h = msg->data;
|
2016-10-24 02:14:20 +00:00
|
|
|
msg->dst = &ss;
|
2016-10-23 22:50:09 +00:00
|
|
|
|
2016-10-24 02:14:51 +00:00
|
|
|
return l2tp_rcvmsg(msg);
|
2016-10-14 14:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int l2tpd_instance_start(struct l2tpd_instance *li)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
INIT_LLIST_HEAD(&li->connections);
|
|
|
|
|
2016-10-23 21:16:54 +00:00
|
|
|
li->l2tp_ofd.when = BSC_FD_READ;
|
|
|
|
li->l2tp_ofd.cb = l2tp_ip_read_cb;
|
|
|
|
li->l2tp_ofd.data = li;
|
|
|
|
|
2016-10-14 14:47:46 +00:00
|
|
|
rc = osmo_sock_init_ofd(&li->l2tp_ofd, AF_INET, SOCK_RAW,
|
|
|
|
IPPROTO_L2TP, li->cfg.bind_ip, 0, 0);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-23 21:01:23 +00:00
|
|
|
/* default categories */
|
|
|
|
static struct log_info_cat l2tp_categories[] = {
|
|
|
|
[DL2TP] = {
|
|
|
|
.name = "DL2TP",
|
|
|
|
.description = "L2TP logging messages",
|
|
|
|
.enabled = 1, .loglevel = LOGL_DEBUG,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct log_info l2tp_log_info = {
|
|
|
|
.cat = l2tp_categories,
|
|
|
|
.num_cat = ARRAY_SIZE(l2tp_categories),
|
|
|
|
};
|
2016-10-14 14:47:46 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int rc;
|
2016-10-23 21:29:57 +00:00
|
|
|
struct log_target *stderr_target;
|
2016-10-23 21:17:13 +00:00
|
|
|
void *tall_l2tp_ctx = talloc_named_const(NULL, 0, "l2tpd");
|
|
|
|
|
2016-10-23 21:30:19 +00:00
|
|
|
/* register fsms */
|
|
|
|
osmo_fsm_register(&l2tp_cc_fsm);
|
|
|
|
osmo_fsm_register(&l2tp_ic_fsm);
|
|
|
|
|
2016-10-23 21:17:13 +00:00
|
|
|
l2i = talloc_zero(tall_l2tp_ctx, struct l2tpd_instance);
|
|
|
|
l2i->cfg.bind_ip = "0.0.0.0";
|
|
|
|
|
|
|
|
rc = l2tpd_instance_start(l2i);
|
2016-10-14 14:47:46 +00:00
|
|
|
if (rc < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2016-10-23 21:01:23 +00:00
|
|
|
log_init(&l2tp_log_info, NULL);
|
2016-10-23 21:29:57 +00:00
|
|
|
stderr_target = log_target_create_stderr();
|
|
|
|
log_add_target(stderr_target);
|
|
|
|
log_set_print_filename(stderr_target, 0);
|
|
|
|
|
2016-10-23 21:01:23 +00:00
|
|
|
|
2016-10-14 14:47:46 +00:00
|
|
|
while (1) {
|
|
|
|
osmo_select_main(0);
|
|
|
|
}
|
|
|
|
}
|