summaryrefslogtreecommitdiff
path: root/accel-pptpd
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pptpd')
-rw-r--r--accel-pptpd/ipcp_opt_ipaddr.c59
-rw-r--r--accel-pptpd/lcp_opt_mru.c28
-rw-r--r--accel-pptpd/ppp.c10
-rw-r--r--accel-pptpd/ppp.h3
-rw-r--r--accel-pptpd/pptp.c3
5 files changed, 90 insertions, 13 deletions
diff --git a/accel-pptpd/ipcp_opt_ipaddr.c b/accel-pptpd/ipcp_opt_ipaddr.c
index 206c2e6e..2fa92519 100644
--- a/accel-pptpd/ipcp_opt_ipaddr.c
+++ b/accel-pptpd/ipcp_opt_ipaddr.c
@@ -1,6 +1,10 @@
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <arpa/inet.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <linux/if_ppp.h>
#include "ppp.h"
#include "ppp_ipcp.h"
@@ -72,19 +76,56 @@ static int ipaddr_send_conf_nak(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o
static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr)
{
- struct ipaddr_option_t *ipaddr_opt=container_of(opt,typeof(*ipaddr_opt),opt);
- struct ipcp_opt32_t *opt32=(struct ipcp_opt32_t*)ptr;
-
- if (ipaddr_opt->peer_addr==opt32->val)
- return IPCP_OPT_ACK;
+ struct ipaddr_option_t *ipaddr_opt = container_of(opt,typeof(*ipaddr_opt), opt);
+ struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t*)ptr;
+ struct ifreq ifr;
+ struct sockaddr_in addr;
+ struct npioctl np;
+
+ if (ipaddr_opt->peer_addr == opt32->val)
+ goto ack;
- if (!ipaddr_opt->peer_addr)
- {
- ipaddr_opt->peer_addr=opt32->val;
- return IPCP_OPT_ACK;
+ if (!ipaddr_opt->peer_addr) {
+ ipaddr_opt->peer_addr = opt32->val;
+ goto ack;
}
return IPCP_OPT_NAK;
+
+ack:
+ memset(&ifr, 0, sizeof(ifr));
+ memset(&addr, 0, sizeof(addr));
+
+ sprintf(ifr.ifr_name,"ppp%i",ipcp->ppp->unit_idx);
+
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = ipaddr_opt->addr;
+ memcpy(&ifr.ifr_addr,&addr,sizeof(addr));
+
+ if (ioctl(sock_fd, SIOCSIFADDR, &ifr))
+ log_error("\nipcp: failed to set PA address: %s\n", strerror(errno));
+
+ addr.sin_addr.s_addr = ipaddr_opt->peer_addr;
+ memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr));
+
+ if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr))
+ log_error("\nipcp: failed to set remote PA address: %s\n", strerror(errno));
+
+ if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr))
+ log_error("\nipcp: failed to get interface flags: %s\n", strerror(errno));
+
+ ifr.ifr_flags |= IFF_UP | IFF_POINTOPOINT;
+
+ if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr))
+ log_error("\nipcp: failed to set interface flags: %s\n", strerror(errno));
+
+ np.protocol = PPP_IP;
+ np.mode = NPMODE_PASS;
+
+ if (ioctl(ipcp->ppp->unit_fd, PPPIOCSNPMODE, &np))
+ log_error("\nipcp: failed to set NP mode: %s\n", strerror(errno));
+
+ return IPCP_OPT_ACK;
}
static void ipaddr_print(void (*print)(const char *fmt,...),struct ipcp_option_t *opt, uint8_t *ptr)
diff --git a/accel-pptpd/lcp_opt_mru.c b/accel-pptpd/lcp_opt_mru.c
index 153b0e06..e1c13b47 100644
--- a/accel-pptpd/lcp_opt_mru.c
+++ b/accel-pptpd/lcp_opt_mru.c
@@ -1,16 +1,23 @@
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <arpa/inet.h>
+#include <net/if.h>
+#include <linux/if_ppp.h>
+#include <sys/ioctl.h>
#include "ppp.h"
#include "ppp_lcp.h"
#include "log.h"
+#define MAX_MTU 1436
+
static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp);
static void mru_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt);
static int mru_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
+static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
static void mru_print(void (*print)(const char *fmt,...),struct lcp_option_t*, uint8_t *ptr);
struct mru_option_t
@@ -26,6 +33,7 @@ static struct lcp_option_handler_t mru_opt_hnd=
.send_conf_req=mru_send_conf_req,
.send_conf_nak=mru_send_conf_nak,
.recv_conf_req=mru_recv_conf_req,
+ .recv_conf_ack=mru_recv_conf_ack,
.free=mru_free,
.print=mru_print,
};
@@ -35,7 +43,7 @@ static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp)
struct mru_option_t *mru_opt=malloc(sizeof(*mru_opt));
memset(mru_opt,0,sizeof(*mru_opt));
mru_opt->mtu=0;
- mru_opt->mru=1500;
+ mru_opt->mru=MAX_MTU;
mru_opt->opt.id=CI_MRU;
mru_opt->opt.len=4;
@@ -81,6 +89,24 @@ static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
}else return LCP_OPT_NAK;
}
+static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr)
+{
+ struct mru_option_t *mru_opt = container_of(opt,typeof(*mru_opt), opt);
+ struct ifreq ifr = {
+ .ifr_mtu = mru_opt->mtu,
+ };
+
+ sprintf(ifr.ifr_name,"ppp%i",lcp->ppp->unit_idx);
+
+ if (ioctl(lcp->ppp->unit_fd, PPPIOCSMRU, &mru_opt->mru))
+ log_error("\nlcp:mru: failed to set MRU: %s\n", strerror(errno));
+
+ if (ioctl(sock_fd, SIOCSIFMTU, &ifr))
+ log_error("\nlcp:mru: failed to set MTU: %s\n", strerror(errno));
+
+ return 0;
+}
+
static void mru_print(void (*print)(const char *fmt,...),struct lcp_option_t *opt, uint8_t *ptr)
{
struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt);
diff --git a/accel-pptpd/ppp.c b/accel-pptpd/ppp.c
index 7f15c8af..d1b38832 100644
--- a/accel-pptpd/ppp.c
+++ b/accel-pptpd/ppp.c
@@ -480,3 +480,13 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *ppp, struct ppp_layer
return NULL;
}
+
+int sock_fd;
+static void __init ppp_init(void)
+{
+ sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock_fd < 0) {
+ perror("socket");
+ _exit(EXIT_FAILURE);
+ }
+}
diff --git a/accel-pptpd/ppp.h b/accel-pptpd/ppp.h
index a7665908..b3b1be89 100644
--- a/accel-pptpd/ppp.h
+++ b/accel-pptpd/ppp.h
@@ -121,8 +121,6 @@ int establish_ppp(struct ppp_t *ppp);
int ppp_chan_send(struct ppp_t *ppp, void *data, int size);
int ppp_unit_send(struct ppp_t *ppp, void *data, int size);
-void ppp_init(void);
-
struct ppp_fsm_t* ppp_lcp_init(struct ppp_t *ppp);
void ppp_layer_started(struct ppp_t *ppp,struct ppp_layer_data_t*);
void ppp_layer_finished(struct ppp_t *ppp,struct ppp_layer_data_t*);
@@ -136,4 +134,5 @@ int ppp_register_layer(const char *name, struct ppp_layer_t *);
void ppp_unregister_layer(struct ppp_layer_t *);
struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t *);
+extern int sock_fd; // internet socket for ioctls
#endif
diff --git a/accel-pptpd/pptp.c b/accel-pptpd/pptp.c
index a8aef873..3104e60e 100644
--- a/accel-pptpd/pptp.c
+++ b/accel-pptpd/pptp.c
@@ -8,6 +8,7 @@
#include <time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <sys/socket.h>
#include "if_pppox.h"
@@ -445,7 +446,7 @@ static struct pptp_serv_t serv=
.ctx.close=pptp_serv_close,
};
-void __init pptp_init(void)
+static void __init pptp_init(void)
{
struct sockaddr_in addr;