[AX.25]: Reference counting for AX.25 routes.
[safe/jmp/linux-2.6] / include / net / ax25.h
index 7ddf6b2..69374cd 100644 (file)
@@ -6,7 +6,6 @@
 #ifndef _AX25_H
 #define _AX25_H 
 
-#include <linux/config.h>
 #include <linux/ax25.h>
 #include <linux/spinlock.h>
 #include <linux/timer.h>
 /* Define Link State constants. */
 
 enum { 
-       AX25_STATE_0,
-       AX25_STATE_1,
-       AX25_STATE_2,
-       AX25_STATE_3,
-       AX25_STATE_4
+       AX25_STATE_0,                   /* Listening */
+       AX25_STATE_1,                   /* SABM sent */
+       AX25_STATE_2,                   /* DISC sent */
+       AX25_STATE_3,                   /* Established */
+       AX25_STATE_4                    /* Recovery */
 };
 
 #define AX25_MODULUS           8       /*  Standard AX.25 modulus */
@@ -110,8 +109,15 @@ enum {
 enum {
        AX25_PROTO_STD_SIMPLEX,
        AX25_PROTO_STD_DUPLEX,
+#ifdef CONFIG_AX25_DAMA_SLAVE
        AX25_PROTO_DAMA_SLAVE,
-       AX25_PROTO_DAMA_MASTER
+#ifdef CONFIG_AX25_DAMA_MASTER
+       AX25_PROTO_DAMA_MASTER,
+#define AX25_PROTO_MAX AX25_PROTO_DAMA_MASTER
+#endif
+#endif
+       __AX25_PROTO_MAX,
+       AX25_PROTO_MAX = __AX25_PROTO_MAX -1
 };
 
 enum {
@@ -138,14 +144,14 @@ enum {
 #define        AX25_DEF_CONMODE        2                       /* Connected mode allowed */
 #define        AX25_DEF_WINDOW         2                       /* Window=2 */
 #define        AX25_DEF_EWINDOW        32                      /* Module-128 Window=32 */
-#define        AX25_DEF_T1             (10 * HZ)               /* T1=10s */
-#define        AX25_DEF_T2             (3 * HZ)                /* T2=3s  */
-#define        AX25_DEF_T3             (300 * HZ)              /* T3=300s */
+#define        AX25_DEF_T1             10000                   /* T1=10s */
+#define        AX25_DEF_T2             3000                    /* T2=3s  */
+#define        AX25_DEF_T3             300000                  /* T3=300s */
 #define        AX25_DEF_N2             10                      /* N2=10 */
-#define AX25_DEF_IDLE          (0 * 60 * HZ)           /* Idle=None */
+#define AX25_DEF_IDLE          0                       /* Idle=None */
 #define AX25_DEF_PACLEN                256                     /* Paclen=256 */
 #define        AX25_DEF_PROTOCOL       AX25_PROTO_STD_SIMPLEX  /* Standard AX.25 */
-#define AX25_DEF_DS_TIMEOUT    (3 * 60 * HZ)           /* DAMA timeout 3 minutes */
+#define AX25_DEF_DS_TIMEOUT    180000                  /* DAMA timeout 3 minutes */
 
 typedef struct ax25_uid_assoc {
        struct hlist_node       uid_node;
@@ -171,19 +177,31 @@ typedef struct {
        ax25_address            calls[AX25_MAX_DIGIS];
        unsigned char           repeated[AX25_MAX_DIGIS];
        unsigned char           ndigi;
-       char                    lastrepeat;
+       signed char             lastrepeat;
 } ax25_digi;
 
 typedef struct ax25_route {
        struct ax25_route       *next;
-       atomic_t                ref;
+       atomic_t                refcount;
        ax25_address            callsign;
        struct net_device       *dev;
        ax25_digi               *digipeat;
        char                    ip_mode;
-       struct timer_list       timer;
 } ax25_route;
 
+static inline void ax25_hold_route(ax25_route *ax25_rt)
+{
+       atomic_inc(&ax25_rt->refcount);
+}
+
+extern void __ax25_put_route(ax25_route *ax25_rt);
+
+static inline void ax25_put_route(ax25_route *ax25_rt)
+{
+       if (atomic_dec_and_test(&ax25_rt->refcount))
+               __ax25_put_route(ax25_rt);
+}
+
 typedef struct {
        char                    slave;                  /* slave_mode?   */
        struct timer_list       slave_timer;            /* timeout timer */
@@ -237,8 +255,7 @@ typedef struct ax25_cb {
 static __inline__ void ax25_cb_put(ax25_cb *ax25)
 {
        if (atomic_dec_and_test(&ax25->refcount)) {
-               if (ax25->digipeat)
-                       kfree(ax25->digipeat);
+               kfree(ax25->digipeat);
                kfree(ax25);
        }
 }
@@ -343,17 +360,11 @@ extern int  ax25_check_iframes_acked(ax25_cb *, unsigned short);
 extern void ax25_rt_device_down(struct net_device *);
 extern int  ax25_rt_ioctl(unsigned int, void __user *);
 extern struct file_operations ax25_route_fops;
+extern ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev);
 extern int  ax25_rt_autobind(ax25_cb *, ax25_address *);
-extern ax25_route *ax25_rt_find_route(ax25_route *, ax25_address *,
-       struct net_device *);
 extern struct sk_buff *ax25_rt_build_path(struct sk_buff *, ax25_address *, ax25_address *, ax25_digi *);
 extern void ax25_rt_free(void);
 
-static inline void ax25_put_route(ax25_route *ax25_rt)
-{
-       atomic_dec(&ax25_rt->ref);
-}
-
 /* ax25_std_in.c */
 extern int  ax25_std_frame_in(ax25_cb *, struct sk_buff *, int);