All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH] ppp: change MTU on TUN device when MRU option received
Date: Thu, 22 Apr 2010 15:49:15 -0700	[thread overview]
Message-ID: <1271976555-10393-1-git-send-email-kristen@linux.intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

---
 gatchat/gatppp.c  |    3 ++-
 gatchat/ppp.h     |    2 +-
 gatchat/ppp_net.c |   23 ++++++++++++++++++++---
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 705a298..fc6769c 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -411,7 +411,8 @@ void ppp_net_up_notify(GAtPPP *ppp, const char *ip,
 {
 	ppp->net = ppp_net_new(ppp);
 
-	ppp_net_set_mtu(ppp->net, ppp->mtu);
+	if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
+		g_printerr("Unable to set MTU\n");
 
 	if (ppp->connect_cb == NULL)
 		return;
diff --git a/gatchat/ppp.h b/gatchat/ppp.h
index 07483a9..c7e6d24 100644
--- a/gatchat/ppp.h
+++ b/gatchat/ppp.h
@@ -103,7 +103,7 @@ struct ppp_net *ppp_net_new(GAtPPP *ppp);
 const char *ppp_net_get_interface(struct ppp_net *net);
 void ppp_net_process_packet(struct ppp_net *net, guint8 *packet);
 void ppp_net_free(struct ppp_net *net);
-void ppp_net_set_mtu(struct ppp_net *net, guint16 mtu);
+gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu);
 
 /* PPP functions related to main GAtPPP object */
 void ppp_debug(GAtPPP *ppp, const char *str);
diff --git a/gatchat/ppp_net.c b/gatchat/ppp_net.c
index c1f2eb4..b8b3355 100644
--- a/gatchat/ppp_net.c
+++ b/gatchat/ppp_net.c
@@ -48,12 +48,29 @@ struct ppp_net {
 	gint mtu;
 };
 
-void ppp_net_set_mtu(struct ppp_net *net, guint16 mtu)
+gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu)
 {
-	if (net == NULL)
-		return;
+	struct ifreq ifr;
+	int sock;
+	int rc;
+
+	if (net == NULL || mtu >= MAX_PACKET)
+		return FALSE;
 
 	net->mtu = mtu;
+
+	sock = socket(AF_INET, SOCK_DGRAM, 0);
+	if (sock < 0)
+		return FALSE;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, net->if_name, sizeof(ifr.ifr_name));
+	ifr.ifr_mtu = mtu;
+
+	rc = ioctl(sock, SIOCSIFMTU, (caddr_t) &ifr);
+
+	close(sock);
+	return (rc < 0) ? FALSE: TRUE;
 }
 
 void ppp_net_process_packet(struct ppp_net *net, guint8 *packet)
-- 
1.6.6.1


             reply	other threads:[~2010-04-22 22:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22 22:49 Kristen Carlson Accardi [this message]
2010-04-22 23:00 ` [PATCH] ppp: change MTU on TUN device when MRU option received Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-04-22 21:15 Kristen Carlson Accardi
2010-04-22 22:10 ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1271976555-10393-1-git-send-email-kristen@linux.intel.com \
    --to=kristen@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.