# ppp with gigawords support

## nicraM

Hi.

I'm trying to enable gigawords in ppp-2.4.5-r1 but i can't find use flag or gentoo method to install it anywher.

i've downloaded gigawords plugin:

```
diff -Naur ppp-2.4.4/pppd/Makefile.linux ppp-2.4.4-patched-fixed/pppd/Makefile.linux

--- ppp-2.4.4/pppd/Makefile.linux   2008-12-12 20:51:47.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/Makefile.linux   2008-12-12 20:45:31.000000000 +0200

@@ -75,6 +75,8 @@

 

 MAXOCTETS=y

 

+LONGCOUNTER=y

+

 INCLUDE_DIRS= -I../include

 

 COMPILE_FLAGS= -DHAVE_PATHS_H -DIPX_CHANGE -DHAVE_MMAP

@@ -193,6 +195,12 @@

      CFLAGS += -DMAXOCTETS

 endif

 

+ifdef LONGCOUNTER

+     CFLAGS += -DLONGCOUNTER

+endif

+

+

+

 INSTALL= install

 

 all: $(TARGETS)

diff -Naur ppp-2.4.4/pppd/main.c ppp-2.4.4-patched-fixed/pppd/main.c

--- ppp-2.4.4/pppd/main.c   2008-12-12 20:51:58.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/main.c   2008-12-12 20:50:17.000000000 +0200

@@ -202,7 +202,10 @@

 static struct timeval start_time;   /* Time when link was started. */

 

 static struct pppd_stats old_link_stats;

+

 struct pppd_stats link_stats;

+struct extended_pppd_stats extended_link_stats;

+

 unsigned link_connect_time;

 int link_stats_valid;

 

@@ -1218,6 +1225,15 @@

 {

     if (!get_ppp_stats(u, &old_link_stats))

    return;

+

+

+#ifdef LONGCOUNTER

+    extended_link_stats.prev_bytes_in = 0;

+    extended_link_stats.prev_bytes_out = 0;

+    extended_link_stats.long_bytes_in = 0;

+    extended_link_stats.long_bytes_out = 0;

+#endif

+    

     gettimeofday(&start_time, NULL);

 }

 

@@ -1242,6 +1258,33 @@

     link_stats.pkts_in   -= old_link_stats.pkts_in;

     link_stats.pkts_out  -= old_link_stats.pkts_out;

 

+#ifdef LONGCOUNTER

+    /* 

+    * Detect rollover 

+    * If value rolled over, add this bytes to "long" counter, then "previous" counter value to zero

+    * It will count also data in next step , which accounted after "rollover"

+    * All this can be done many different ways, but this one - simpliest

+    */

+    

+    if (link_stats.bytes_in < extended_link_stats.prev_bytes_in) {

+   extended_link_stats.long_bytes_in += (unsigned long long) (UINT32_MAX - extended_link_stats.prev_bytes_in);

+   extended_link_stats.prev_bytes_in = 0;

+    }

+

+    if (link_stats.bytes_out < extended_link_stats.prev_bytes_out) {

+   extended_link_stats.long_bytes_out += (unsigned long long) (UINT32_MAX - extended_link_stats.prev_bytes_out);

+   extended_link_stats.prev_bytes_out = 0;

+    }

+

+    /* Add to "long" counter diff of accounted data */

+    extended_link_stats.long_bytes_in += (unsigned long long) (link_stats.bytes_in - extended_link_stats.prev_bytes_in);

+    extended_link_stats.long_bytes_out += (unsigned long long) (link_stats.bytes_out - extended_link_stats.prev_bytes_out);

+

+    extended_link_stats.prev_bytes_in = link_stats.bytes_in;

+    extended_link_stats.prev_bytes_out = link_stats.bytes_out;

+    

+#endif

+

     slprintf(numbuf, sizeof(numbuf), "%u", link_connect_time);

     script_setenv("CONNECT_TIME", numbuf, 0);

     slprintf(numbuf, sizeof(numbuf), "%u", link_stats.bytes_out);

diff -Naur ppp-2.4.4/pppd/plugins/radius/Makefile.linux ppp-2.4.4-patched-fixed/pppd/plugins/radius/Makefile.linux

--- ppp-2.4.4/pppd/plugins/radius/Makefile.linux   2008-12-12 20:51:47.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/plugins/radius/Makefile.linux   2008-12-12 20:45:31.000000000 +0200

@@ -22,6 +22,8 @@

 # Uncomment the next lint to include support for traffic limiting

 MAXOCTETS=y

 

+LONGCOUNTER=y

+

 ifdef CHAPMS

 CFLAGS += -DCHAPMS=1

 ifdef MPPE

@@ -31,6 +33,11 @@

 ifdef MAXOCTETS

 CFLAGS += -DMAXOCTETS=1

 endif

+ifdef LONGCOUNTER

+CFLAGS += -DLONGCOUNTER=1

+endif

+

+

 

 all: $(PLUGIN)

 

diff -Naur ppp-2.4.4/pppd/plugins/radius/etc/dictionary ppp-2.4.4-patched-fixed/pppd/plugins/radius/etc/dictionary

--- ppp-2.4.4/pppd/plugins/radius/etc/dictionary   2002-11-09 13:24:42.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/plugins/radius/etc/dictionary   2008-12-12 20:43:17.000000000 +0200

@@ -82,6 +82,8 @@

 ATTRIBUTE   Acct-Input-Packets   47   integer

 ATTRIBUTE   Acct-Output-Packets   48   integer

 ATTRIBUTE   Acct-Terminate-Cause   49   integer

+ATTRIBUTE   Acct-Input-Gigawords   52   integer

+ATTRIBUTE   Acct-Output-Gigawords   53   integer

 ATTRIBUTE       Chap-Challenge          60      string

 ATTRIBUTE   NAS-Port-Type      61   integer

 ATTRIBUTE   Port-Limit      62   integer

diff -Naur ppp-2.4.4/pppd/plugins/radius/radius.c ppp-2.4.4-patched-fixed/pppd/plugins/radius/radius.c

--- ppp-2.4.4/pppd/plugins/radius/radius.c   2006-05-22 03:01:40.000000000 +0300

+++ ppp-2.4.4-patched-fixed/pppd/plugins/radius/radius.c   2008-12-12 20:43:17.000000000 +0200

@@ -966,11 +966,27 @@

    av_type = link_connect_time;

    rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);

 

+#ifdef LONGCOUNTER

+

+   av_type = extended_link_stats.long_bytes_out % UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_in % UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_out / UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_OUTPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_in / UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_INPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);

+

+#else

    av_type = link_stats.bytes_out;

    rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);

 

    av_type = link_stats.bytes_in;

    rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+#endif

 

    av_type = link_stats.pkts_out;

    rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);

@@ -1114,11 +1130,27 @@

    av_type = link_connect_time;

    rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);

 

+#ifdef LONGCOUNTER

+

+   av_type = extended_link_stats.long_bytes_out % UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_in % UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_out / UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_OUTPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);

+

+   av_type = extended_link_stats.long_bytes_in / UINT32_MAX;

+   rc_avpair_add(&send, PW_ACCT_INPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);

+

+#else

    av_type = link_stats.bytes_out;

    rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);

 

    av_type = link_stats.bytes_in;

    rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);

+#endif

 

    av_type = link_stats.pkts_out;

    rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);

diff -Naur ppp-2.4.4/pppd/plugins/radius/radiusclient.h ppp-2.4.4-patched-fixed/pppd/plugins/radius/radiusclient.h

--- ppp-2.4.4/pppd/plugins/radius/radiusclient.h   2004-11-14 09:26:26.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/plugins/radius/radiusclient.h   2008-12-12 20:43:17.000000000 +0200

@@ -167,6 +167,9 @@

 #define PW_ACCT_TERMINATE_CAUSE      49   /* integer */

 #define PW_ACCT_MULTI_SESSION_ID   50   /* string */

 #define PW_ACCT_LINK_COUNT      51   /* integer */

+/* RFC 2869 */

+#define   PW_ACCT_INPUT_GIGAWORDS      52   /* integer */

+#define   PW_ACCT_OUTPUT_GIGAWORDS   53   /* integer */

 

 /* From RFC 2869 */

 #define PW_ACCT_INTERIM_INTERVAL        85   /* integer */

diff -Naur ppp-2.4.4/pppd/pppd.h ppp-2.4.4-patched-fixed/pppd/pppd.h

--- ppp-2.4.4/pppd/pppd.h   2008-12-12 20:51:44.000000000 +0200

+++ ppp-2.4.4-patched-fixed/pppd/pppd.h   2008-12-12 20:45:26.000000000 +0200

@@ -174,6 +174,14 @@

     unsigned int   bytes_out;

     unsigned int   pkts_in;

     unsigned int   pkts_out;

+

+};

+

+struct extended_pppd_stats {

+    unsigned int   prev_bytes_in;

+    unsigned int   prev_bytes_out;

+    unsigned long long   long_bytes_in;

+    unsigned long long   long_bytes_out;

 };

 

 /* Used for storing a sequence of words.  Usually malloced. */

@@ -231,6 +239,7 @@

 extern GIDSET_TYPE groups[NGROUPS_MAX];   /* groups the user is in */

 extern int   ngroups;   /* How many groups valid in groups */

 extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */

+extern struct extended_pppd_stats extended_link_stats; /* 64-bit counting */

 extern int   link_stats_valid; /* set if link_stats is valid */

 extern unsigned   link_connect_time; /* time the link was up for */

 extern int   using_pty;   /* using pty as device (notty or pty opt.) */
```

i puted it to /etc/portage/plugins/net-dialup/ppp

but ebuild doesn't support epatch_user.

maybe should i create new ebuild, but how?

this patch works fine with this patch when i make it manually.

how should i add gigawords issue for ppp with gentoo method?

----------

## dE_logics

I don't know anything about gigawords, but you may like to use ebuild to manually compile the package using Portage.

ebuild <path to ebuild> setup

ebuild <path to ebuild> unpack

<apply the patch by hand>

ebuild <ebuild> compile

ebuild <path to ebuild> install

ebuild <path to ebuild> qmerge

----------

