   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
-diff -aur --unidirectional-new-file sys/sys/timepps.h FreeBSD-CURRENT/sys/timepps.h
---- sys/sys/timepps.h	2010-12-09 15:46:09.000000000 +1100
-+++ FreeBSD-CURRENT/sys/timepps.h	2010-12-09 16:27:51.000000000 +1100
+@@ -324,6 +330,49 @@ void	getbintime(struct bintime *bt);
+ void	getnanotime(struct timespec *tsp);
+ void	getmicrotime(struct timeval *tvp);
+ 
++/* FFCLOCK specific */
++typedef uint64_t ffcounter_t;
++
++/* Feed-Forward Clock synchronisation structure */
++
++struct ffclock_data
++{
++	/* phat as an int shifted phat_shift to the left */
++	uint64_t phat_int;
++	/* Record of last time update from synchronization algorithm as an int */
++	uint64_t time_int;
++	/* The counter value to convert in seconds */
++	ffcounter_t ffcounter;
++	/* the shift amount for phat_int */
++	uint8_t phat_shift;
++	/* the shift amount for time_int */
++	uint8_t time_shift;
++	/* Warn if stamp is over this many bits */
++	uint8_t countdiff_maxbits;
++};
++
++struct ffclock_estimate
++{
++	volatile uint8_t gen;
++	struct ffclock_data cdata;
++};
++
++/* Current estimate and old one, no locking on the timestamping side */
++struct feedforward_clock
++{
++	volatile uint8_t updated;
++	struct ffclock_estimate *cest;
++	struct ffclock_estimate *ocest;
++	struct ffclock_estimate *ucest;
++};
++
++
++
++ffcounter_t read_ffcounter(void);
++void ffcounter2bintime(ffcounter_t *ffcounter, struct bintime *bt);
++/* FFCLOCK */
++
++
+ /* Other functions */
+ int	itimerdecr(struct itimerval *itp, int usec);
+ int	itimerfix(struct timeval *tv);
+diff -apur --unidirectional-new-file sys/sys/timepps.h FreeBSD-CURRENT/sys/timepps.h
+--- sys/sys/timepps.h	2010-12-09 17:45:11.000000000 +1100
++++ FreeBSD-CURRENT/sys/timepps.h	2010-12-09 17:45:32.000000000 +1100
 @@ -6,6 +6,12 @@
   * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
   * ----------------------------------------------------------------------------

  * $FreeBSD: src/sys/sys/timepps.h,v 1.19 2005/01/07 02:29:24 imp Exp $
  *
  * The is a FreeBSD version of the RFC 2783 API for Pulse Per Second 
diff -aur --unidirectional-new-file sys/sys/timetc.h FreeBSD-CURRENT/sys/timetc.h
--- sys/sys/timetc.h	2010-12-09 15:46:09.000000000 +1100
+++ FreeBSD-CURRENT/sys/timetc.h	2010-12-09 16:27:51.000000000 +1100
@@ -6,6 +6,12 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------

  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -37,9 +43,13 @@
  * $FreeBSD: src/sys/net/bpf.h,v 1.56 2010/10/29 18:41:09 rpaulo Exp $
  */
 
+
+#include "opt_ffclock.h" 
+
 #ifndef _NET_BPF_H_
 #define _NET_BPF_H_
 
+
 /* BSD style release date */
 #define	BPF_RELEASE 199606
 
@@ -169,7 +179,12 @@ enum bpf_direction {
 #define	BPF_T_FAST		0x0100
 #define	BPF_T_MONOTONIC		0x0200
 #define	BPF_T_MONOTONIC_FAST	(BPF_T_FAST | BPF_T_MONOTONIC)
+#ifdef FFCLOCK
+#define	BPF_T_FFCLOCK		0x0400
+#define	BPF_T_FLAG_MASK		0x0700
+#else
 #define	BPF_T_FLAG_MASK		0x0300
+#endif
 #define	BPF_T_FORMAT(t)		((t) & BPF_T_FORMAT_MASK)
 #define	BPF_T_FLAG(t)		((t) & BPF_T_FLAG_MASK)
 #define	BPF_T_VALID(t)						\
@@ -185,6 +200,11 @@ enum bpf_direction {
 #define	BPF_T_MICROTIME_MONOTONIC_FAST	(BPF_T_MICROTIME | BPF_T_MONOTONIC_FAST)
 #define	BPF_T_NANOTIME_MONOTONIC_FAST	(BPF_T_NANOTIME | BPF_T_MONOTONIC_FAST)
 #define	BPF_T_BINTIME_MONOTONIC_FAST	(BPF_T_BINTIME | BPF_T_MONOTONIC_FAST)
+#ifdef FFCLOCK
+#define BPF_T_MICROTIME_FFCLOCK		(BPF_T_MICROTIME | BPF_T_FFCLOCK)
+#define BPF_T_NANOTIME_FFCLOCK		(BPF_T_NANOTIME | BPF_T_FFCLOCK)
+#define BPF_T_BINTIME_FFCLOCK		(BPF_T_BINTIME | BPF_T_FFCLOCK)
+#endif
 
 /*
  * Structure prepended to each packet.
@@ -193,14 +213,39 @@ struct bpf_ts {
 	bpf_int64	bt_sec;		/* seconds */
 	bpf_u_int64	bt_frac;	/* fraction */
 };
+
+#ifdef FFCLOCK
 struct bpf_xhdr {
 	struct bpf_ts	bh_tstamp;	/* time stamp */
 	bpf_u_int32	bh_caplen;	/* length of captured portion */
 	bpf_u_int32	bh_datalen;	/* original length of packet */
 	u_short		bh_hdrlen;	/* length of bpf header (this struct
 					   plus alignment padding) */
+	u_short		padding;		/* padding to align the fields */
+	ffcounter_t	ffcounter_stamp;	/* feed-forward counter timestamp */
 };
+#else
+struct bpf_xhdr {
+	struct bpf_ts	bh_tstamp;	/* time stamp */
+	bpf_u_int32	bh_caplen;	/* length of captured portion */
+	bpf_u_int32	bh_datalen;	/* original length of packet */
+	u_short		bh_hdrlen;	/* length of bpf header (this struct
+					   plus alignment padding) */
+};
+#endif
+
 /* Obsolete */
+#ifdef FFCLOCK
+struct bpf_hdr {
+	struct timeval	bh_tstamp;	/* time stamp */
+	bpf_u_int32	bh_caplen;	/* length of captured portion */
+	bpf_u_int32	bh_datalen;	/* original length of packet */
+	u_short		bh_hdrlen;	/* length of bpf header (this struct
+					   plus alignment padding) */
+	u_short		padding;		/* padding to align the fields */
+	ffcounter_t	ffcounter_stamp;	/* feed-forward counter timestamp */
+};
+#else
 struct bpf_hdr {
 	struct timeval	bh_tstamp;	/* time stamp */
 	bpf_u_int32	bh_caplen;	/* length of captured portion */
@@ -208,6 +253,7 @@ struct bpf_hdr {
 	u_short		bh_hdrlen;	/* length of bpf header (this struct
 					   plus alignment padding) */
 };
+#endif
 #ifdef _KERNEL
 #define	MTAG_BPF		0x627066
 #define	MTAG_BPF_TIMESTAMP	0
diff -apur --unidirectional-new-file sys/sys/time.h FreeBSD-CURRENT/sys/time.h
--- sys/sys/time.h	2010-12-09 17:45:11.000000000 +1100
+++ FreeBSD-CURRENT/sys/time.h	2010-12-09 17:45:32.000000000 +1100
@@ -2,6 +2,12 @@
  * Copyright (C) 1982, 1986, 1993
  *	The Regents of the University of California.  All rights reserved.
