* [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
@ 2006-02-15 22:22 Shaun Pereira
2006-02-15 22:35 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 7+ messages in thread
From: Shaun Pereira @ 2006-02-15 22:22 UTC (permalink / raw)
To: netdev, linux-kenel, x25 maintainer, David S. Miller
Cc: Arnd Bergmann, Andre Hendry
This patch is a re-submit of an earlier patch submitted by Andrew Hendry
that did not make it into the Linux Kernel. Here is some more
information about this patch. Hope this is helpful.
This patch allows use of the optional user facility to insert ITU-T
(http://www.itu.int/ITU-T/) specified DTE facilities in call set-up x25
packets. As this feature is optional; no facilities will be added if the
ioctl is not used, and call setup packet remains the same as before.
If the ioctls provided by the patch are used, then a facility marker
will be added to the x25 packet header so that the called dte address
extension facility can be differentiated from other types of facilities
(as described in the ITU-T X.25 recommendation) that are also allowed in
the x25 packet header.
Facility markers are made up of two octets, and may be present in the
x25 packet headers of call-request, incoming call, call accepted, clear
request, and clear indication packets. The first of the two octets
represents the facility code field and is set to zero by this patch. The
second octet of the marker represents the facility parameter field and
is set to 0x0F because the marker will be inserted before ITU-T type DTE
facilities.
Since according to ITU-T X.25 Recommendation X.25(10/96)- 7.1 "All
networks will support the facility markers with a facility parameter
field set to all ones or to 00001111", therefore this patch should work
with all x.25 networks.
While there are many ITU-T DTE facilities, this patch implements only
the called and calling address extension, with placeholders in the
x25_dte_facilities structure for the rest of the facilities.
Testing
This patch was tested using a cisco xot router connected on its serial
ports to an X.25 network, and on its lan ports to a host running an xotd
daemon.
It is also possible to test this patch using an xotd daemon and an
x25tap patch, where the xotd daemons work back-to-back without actually
using an x.25 network. See www.fyonne.net for details on how to do
this.
Signed-off-by:Shaun Pereira <spereira@tusc.com.au>
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/linux/x25.h
linux-2.6.16-rc3/include/linux/x25.h
--- linux-2.6.16-rc3-vanilla/include/linux/x25.h 2006-02-15
10:58:02.000000000 +1100
+++ linux-2.6.16-rc3/include/linux/x25.h 2006-02-15 11:15:32.000000000
+1100
@@ -11,6 +11,8 @@
#ifndef X25_KERNEL_H
#define X25_KERNEL_H
+#include <linux/types.h>
+
#define SIOCX25GSUBSCRIP (SIOCPROTOPRIVATE + 0)
#define SIOCX25SSUBSCRIP (SIOCPROTOPRIVATE + 1)
#define SIOCX25GFACILITIES (SIOCPROTOPRIVATE + 2)
@@ -21,6 +23,8 @@
#define SIOCX25SCUDMATCHLEN (SIOCPROTOPRIVATE + 7)
#define SIOCX25CALLACCPTAPPRV (SIOCPROTOPRIVATE + 8)
#define SIOCX25SENDCALLACCPT (SIOCPROTOPRIVATE + 9)
+#define SIOCX25GDTEFACILITIES (SIOCPROTOPRIVATE + 10)
+#define SIOCX25SDTEFACILITIES (SIOCPROTOPRIVATE + 11)
/*
* Values for {get,set}sockopt.
@@ -77,6 +81,8 @@ struct x25_subscrip_struct {
#define X25_MASK_PACKET_SIZE 0x04
#define X25_MASK_WINDOW_SIZE 0x08
+#define X25_MASK_CALLING_AE 0x10
+#define X25_MASK_CALLED_AE 0x20
/*
@@ -99,6 +105,26 @@ struct x25_facilities {
};
/*
+* ITU DTE facilities
+* Only the called and calling address
+* extension are currently implemented.
+* The rest are in place to avoid the struct
+* changing size if someone needs them later
+*/
+
+struct x25_dte_facilities {
+ __u16 delay_cumul;
+ __u16 delay_target;
+ __u16 delay_max;
+ __u8 min_throughput;
+ __u8 expedited;
+ __u8 calling_len;
+ __u8 called_len;
+ __u8 calling_ae[20];
+ __u8 called_ae[20];
+};
+
+/*
* Call User Data structure.
*/
struct x25_calluserdata {
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/net/x25.h
linux-2.6.16-rc3/include/net/x25.h
--- linux-2.6.16-rc3-vanilla/include/net/x25.h 2006-02-15
10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/include/net/x25.h 2006-02-15 11:15:32.000000000
+1100
@@ -101,9 +101,16 @@ enum {
#define X25_FAC_PACKET_SIZE 0x42
#define X25_FAC_WINDOW_SIZE 0x43
-#define X25_MAX_FAC_LEN 20 /* Plenty to spare */
+#define X25_MAX_FAC_LEN 60
#define X25_MAX_CUD_LEN 128
+#define X25_FAC_CALLING_AE 0xCB
+#define X25_FAC_CALLED_AE 0xC9
+
+#define X25_MARKER 0x00
+#define X25_DTE_SERVICES 0x0F
+#define X25_MAX_AE_LEN 32
+
/**
* struct x25_route - x25 routing entry
* @node - entry in x25_list_lock
@@ -148,6 +155,7 @@ struct x25_sock {
struct timer_list timer;
struct x25_causediag causediag;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
struct x25_calluserdata calluserdata;
unsigned long vc_facil_mask; /* inc_call facilities mask */
};
@@ -180,9 +188,9 @@ extern void x25_establish_link(struct x2
extern void x25_terminate_link(struct x25_neigh *);
/* x25_facilities.c */
-extern int x25_parse_facilities(struct sk_buff *, struct
x25_facilities *, unsigned long *);
-extern int x25_create_facilities(unsigned char *, struct
x25_facilities *, unsigned long);
-extern int x25_negotiate_facilities(struct sk_buff *, struct sock *,
struct x25_facilities *);
+extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities
*, struct x25_dte_facilities *, unsigned long *);
+extern int x25_create_facilities(unsigned char *, struct x25_facilities
*, struct x25_dte_facilities *, unsigned long);
+extern int x25_negotiate_facilities(struct sk_buff *, struct sock *,
struct x25_facilities *, struct x25_dte_facilities *);
extern void x25_limit_facilities(struct x25_facilities *, struct
x25_neigh *);
/* x25_in.c */
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/af_x25.c
linux-2.6.16-rc3/net/x25/af_x25.c
--- linux-2.6.16-rc3-vanilla/net/x25/af_x25.c 2006-02-15
11:15:10.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/af_x25.c 2006-02-15 11:15:32.000000000
+1100
@@ -524,6 +524,13 @@ static int x25_create(struct socket *soc
x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE;
x25->facilities.throughput = X25_DEFAULT_THROUGHPUT;
x25->facilities.reverse = X25_DEFAULT_REVERSE;
+ x25->dte_facilities.calling_len = 0;
+ x25->dte_facilities.called_len = 0;
+ memset(x25->dte_facilities.called_ae, '\0',
+ sizeof(x25->dte_facilities.called_ae));
+ memset(x25->dte_facilities.calling_ae, '\0',
+ sizeof(x25->dte_facilities.calling_ae));
+
rc = 0;
out:
return rc;
@@ -560,6 +567,7 @@ static struct sock *x25_make_new(struct
x25->t2 = ox25->t2;
x25->facilities = ox25->facilities;
x25->qbitincl = ox25->qbitincl;
+ x25->dte_facilities = ox25->dte_facilities;
x25->cudmatchlength = ox25->cudmatchlength;
x25->accptapprv = ox25->accptapprv;
@@ -839,6 +847,7 @@ int x25_rx_call_request(struct sk_buff *
struct x25_sock *makex25;
struct x25_address source_addr, dest_addr;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
int len, rc;
/*
@@ -875,7 +884,8 @@ int x25_rx_call_request(struct sk_buff *
/*
* Try to reach a compromise on the requested facilities.
*/
- if ((len = x25_negotiate_facilities(skb, sk, &facilities)) == -1)
+ if ((len = x25_negotiate_facilities(skb, sk, &facilities,
+ &dte_facilities)) == -1)
goto out_sock_put;
/*
@@ -906,9 +916,12 @@ int x25_rx_call_request(struct sk_buff *
makex25->source_addr = source_addr;
makex25->neighbour = nb;
makex25->facilities = facilities;
+ makex25->dte_facilities= dte_facilities;
makex25->vc_facil_mask = x25_sk(sk)->vc_facil_mask;
/* ensure no reverse facil on accept */
makex25->vc_facil_mask &= ~X25_MASK_REVERSE;
+ /* ensure no calling address extension on accept */
+ makex25->vc_facil_mask &= ~X25_MASK_CALLING_AE;
makex25->cudmatchlength = x25_sk(sk)->cudmatchlength;
/* Normally all calls are accepted immediatly */
@@ -1315,6 +1328,34 @@ static int x25_ioctl(struct socket *sock
break;
}
+ case SIOCX25GDTEFACILITIES: {
+ rc = copy_to_user(argp, &x25->dte_facilities,
+ sizeof(x25->dte_facilities)) ? -EFAULT : 0;
+ break;
+ }
+
+ case SIOCX25SDTEFACILITIES: {
+ struct x25_dte_facilities dtefacs;
+ rc = -EFAULT;
+ if (copy_from_user(&dtefacs, argp, sizeof(dtefacs)))
+ break;
+ rc = -EINVAL;
+ if (sk->sk_state != TCP_LISTEN &&
+ sk->sk_state != TCP_CLOSE)
+ break;
+ if (dtefacs.calling_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.calling_ae == NULL)
+ break;
+ if (dtefacs.called_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.called_ae == NULL)
+ break;
+ x25->dte_facilities = dtefacs;
+ rc = 0;
+ break;
+ }
+
case SIOCX25GCALLUSERDATA: {
struct x25_calluserdata cud = x25->calluserdata;
rc = copy_to_user(argp, &cud,
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c
linux-2.6.16-rc3/net/x25/x25_facilities.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c 2006-02-15
10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_facilities.c 2006-02-15
11:15:32.000000000 +1100
@@ -28,11 +28,12 @@
#include <net/x25.h>
/*
- * Parse a set of facilities into the facilities structure.
Unrecognised
+ * Parse a set of facilities into the facilities structures.
Unrecognised
* facilities are written to the debug log file.
*/
int x25_parse_facilities(struct sk_buff *skb,
struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
unsigned long *vc_fac_mask)
{
unsigned char *p = skb->data;
@@ -40,6 +41,16 @@ int x25_parse_facilities(struct sk_buff
*vc_fac_mask = 0;
+ /* The kernel knows which facilities were set on an incoming call
+ * but currently this information is not available to userspace.
+ * Here we give userspace who read incoming call facilities
+ * 0 length to indicate it wasn't set.
+ */
+ dte_facs->calling_len = 0;
+ dte_facs->called_len = 0;
+ memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae));
+ memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae));
+
while (len > 0) {
switch (*p & X25_FAC_CLASS_MASK) {
case X25_FAC_CLASS_A:
@@ -74,6 +85,10 @@ int x25_parse_facilities(struct sk_buff
facilities->throughput = p[1];
*vc_fac_mask |= X25_MASK_THROUGHPUT;
break;
+
+ case X25_MARKER:
+ break;
+
default:
printk(KERN_DEBUG "X.25: unknown facility "
"%02X, value %02X\n",
@@ -112,9 +127,30 @@ int x25_parse_facilities(struct sk_buff
len -= 4;
break;
case X25_FAC_CLASS_D:
- printk(KERN_DEBUG "X.25: unknown facility %02X, "
- "length %d, values %02X, %02X, %02X, %02X\n",
- p[0], p[1], p[2], p[3], p[4], p[5]);
+ switch (*p) {
+ case X25_FAC_CALLING_AE:
+ if (p[1] > 33)
+ break;
+ dte_facs->calling_len = p[2];
+ memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLING_AE;
+ break;
+
+ case X25_FAC_CALLED_AE:
+ if (p[1] > 33)
+ break;
+ dte_facs->called_len = p[2];
+ memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLED_AE;
+ break;
+
+ default:
+ printk(KERN_DEBUG "X.25: unknown facility %02X,"
+ "length %d, values %02X, %02X, %02X, %02X\n",
+ p[0], p[1], p[2], p[3], p[4], p[5]);
+ break;
+ }
+
len -= p[1] + 2;
p += p[1] + 2;
break;
@@ -129,6 +165,7 @@ int x25_parse_facilities(struct sk_buff
*/
int x25_create_facilities(unsigned char *buffer,
struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
unsigned long facil_mask)
{
unsigned char *p = buffer + 1;
@@ -168,6 +205,34 @@ int x25_create_facilities(unsigned char
*p++ = facilities->winsize_out ? : facilities->winsize_in;
}
+ if ((facil_mask & X25_MASK_CALLING_AE) ||
+ (facil_mask & X25_MASK_CALLED_AE)) {
+ *p++ = X25_MARKER;
+ *p++ = X25_DTE_SERVICES;
+ }
+
+ if (dte_facs->calling_len && (facil_mask & X25_MASK_CALLING_AE)) {
+ unsigned bytecount = (dte_facs->calling_len % 2) ?
+ dte_facs->calling_len / 2 + 1 :
+ dte_facs->calling_len / 2;
+ *p++ = X25_FAC_CALLING_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->calling_len;
+ memcpy(p, dte_facs->calling_ae, bytecount);
+ p+=bytecount;
+ }
+
+ if (dte_facs->called_len && (facil_mask & X25_MASK_CALLED_AE)) {
+ unsigned bytecount = (dte_facs->called_len % 2) ?
+ dte_facs->called_len / 2 + 1 :
+ dte_facs->called_len / 2;
+ *p++ = X25_FAC_CALLED_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->called_len;
+ memcpy(p, dte_facs->called_ae, bytecount);
+ p+=bytecount;
+ }
+
len = p - buffer;
buffer[0] = len - 1;
@@ -180,7 +245,8 @@ int x25_create_facilities(unsigned char
* The only real problem is with reverse charging.
*/
int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
- struct x25_facilities *new)
+ struct x25_facilities *new,
+ struct x25_dte_facilities *dte)
{
struct x25_sock *x25 = x25_sk(sk);
struct x25_facilities *ours = &x25->facilities;
@@ -190,7 +256,7 @@ int x25_negotiate_facilities(struct sk_b
memset(&theirs, 0, sizeof(theirs));
memcpy(new, ours, sizeof(*new));
- len = x25_parse_facilities(skb, &theirs, &x25->vc_facil_mask);
+ len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask);
/*
* They want reverse charging, we won't accept it.
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_in.c
linux-2.6.16-rc3/net/x25/x25_in.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_in.c 2006-02-15
10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_in.c 2006-02-15 11:15:32.000000000
+1100
@@ -106,7 +106,8 @@ static int x25_state1_machine(struct soc
skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr));
skb_pull(skb,
x25_parse_facilities(skb, &x25->facilities,
- &x25->vc_facil_mask));
+ &x25->dte_facilities,
+ &x25->vc_facil_mask));
/*
* Copy any Call User Data.
*/
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c
linux-2.6.16-rc3/net/x25/x25_subr.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c 2006-02-15
10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_subr.c 2006-02-15 11:15:32.000000000
+1100
@@ -191,7 +191,8 @@ void x25_write_internal(struct sock *sk,
memcpy(dptr, addresses, len);
len = x25_create_facilities(facilities,
&x25->facilities,
- x25->neighbour->global_facil_mask);
+ &x25->dte_facilities,
+ x25->neighbour->global_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
dptr = skb_put(skb, x25->calluserdata.cudlength);
@@ -206,6 +207,7 @@ void x25_write_internal(struct sock *sk,
*dptr++ = 0x00; /* Address lengths */
len = x25_create_facilities(facilities,
&x25->facilities,
+ &x25->dte_facilities,
x25->vc_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
2006-02-15 22:22 Shaun Pereira
@ 2006-02-15 22:35 ` Arnaldo Carvalho de Melo
2006-02-16 5:40 ` Shaun Pereira
0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2006-02-15 22:35 UTC (permalink / raw)
To: spereira
Cc: netdev, linux-kenel, x25 maintainer, David S. Miller,
Arnd Bergmann, Andre Hendry
On 2/15/06, Shaun Pereira <spereira@tusc.com.au> wrote:
> + switch (*p) {
> + case X25_FAC_CALLING_AE:
> + if (p[1] > 33)
> + break;
> + dte_facs->calling_len = p[2];
> + memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
> + *vc_fac_mask |= X25_MASK_CALLING_AE;
> + break;
Can this '33' magic number be replaced with a define or sizeof(something)?
- Arnaldo
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
@ 2006-02-15 22:41 Shaun Pereira
0 siblings, 0 replies; 7+ messages in thread
From: Shaun Pereira @ 2006-02-15 22:41 UTC (permalink / raw)
To: linux-kenel, netdev, David S. Miller
32 bit modular socket ioctl emulation for 64 bit kernel
This patch is a re-submit of an earlier patch submitted by Andrew Hendry
that did not make it into the Linux Kernel. Here is some more information
about this patch.
This patch allows use of the optional user facility to insert ITU-T
(http://www.itu.int/ITU-T/) specified DTE facilities in call set-up x25 packets.
This feature is optional; no facilities will be added if the ioctl is not used,
and call setup packet remains the same as before.
If the ioctls provided by the patch are used, then a facility marker will be
added to the x25 packet header so that the called dte address extension
facility can be differentiated from other types of facilities (as described
in the ITU-T X.25 recommendation) that are also allowed in the x25 packet header.
Facility markers are made up of two octets, and may be present in the x25 packet
headers of call-request, incoming call, call accepted, clear request,
and clear indication packets. The first of the two octets represents the
facility code field and is set to zero by this patch. The second octet of the
marker represents the facility parameter field and is set to 0x0F because the
marker will be inserted before ITU-T type DTE facilities.
Since according to ITU-T X.25 Recommendation X.25(10/96)- 7.1 "All networks
will support the facility markers with a facility parameter field set to
all ones or to 00001111", therefore this patch should work with all x.25
networks.
While there are many ITU-T DTE facilities, this patch implements only the
called and calling address extension, with placeholders in the x25_dte_facilities
structure for the rest of the facilities.
Testing
This patch was tested using a cisco xot router connected on its serial ports
to an X.25 network, and on its lan ports to a host running an xotd daemon.
It is also possible to test this patch using an xotd daemon and an x25tap patch,
where the xotd daemons work back-to-back without actually using an x.25 network.
See www.fyonne.net for details on how to do this.
Signed-off-by:Shaun Pereira <spereira@tusc.com.au>
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/linux/x25.h linux-2.6.16-rc3/include/linux/x25.h
--- linux-2.6.16-rc3-vanilla/include/linux/x25.h 2006-02-15 10:58:02.000000000 +1100
+++ linux-2.6.16-rc3/include/linux/x25.h 2006-02-15 11:15:32.000000000 +1100
@@ -11,6 +11,8 @@
#ifndef X25_KERNEL_H
#define X25_KERNEL_H
+#include <linux/types.h>
+
#define SIOCX25GSUBSCRIP (SIOCPROTOPRIVATE + 0)
#define SIOCX25SSUBSCRIP (SIOCPROTOPRIVATE + 1)
#define SIOCX25GFACILITIES (SIOCPROTOPRIVATE + 2)
@@ -21,6 +23,8 @@
#define SIOCX25SCUDMATCHLEN (SIOCPROTOPRIVATE + 7)
#define SIOCX25CALLACCPTAPPRV (SIOCPROTOPRIVATE + 8)
#define SIOCX25SENDCALLACCPT (SIOCPROTOPRIVATE + 9)
+#define SIOCX25GDTEFACILITIES (SIOCPROTOPRIVATE + 10)
+#define SIOCX25SDTEFACILITIES (SIOCPROTOPRIVATE + 11)
/*
* Values for {get,set}sockopt.
@@ -77,6 +81,8 @@ struct x25_subscrip_struct {
#define X25_MASK_PACKET_SIZE 0x04
#define X25_MASK_WINDOW_SIZE 0x08
+#define X25_MASK_CALLING_AE 0x10
+#define X25_MASK_CALLED_AE 0x20
/*
@@ -99,6 +105,26 @@ struct x25_facilities {
};
/*
+* ITU DTE facilities
+* Only the called and calling address
+* extension are currently implemented.
+* The rest are in place to avoid the struct
+* changing size if someone needs them later
+*/
+
+struct x25_dte_facilities {
+ __u16 delay_cumul;
+ __u16 delay_target;
+ __u16 delay_max;
+ __u8 min_throughput;
+ __u8 expedited;
+ __u8 calling_len;
+ __u8 called_len;
+ __u8 calling_ae[20];
+ __u8 called_ae[20];
+};
+
+/*
* Call User Data structure.
*/
struct x25_calluserdata {
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/net/x25.h linux-2.6.16-rc3/include/net/x25.h
--- linux-2.6.16-rc3-vanilla/include/net/x25.h 2006-02-15 10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/include/net/x25.h 2006-02-15 11:15:32.000000000 +1100
@@ -101,9 +101,16 @@ enum {
#define X25_FAC_PACKET_SIZE 0x42
#define X25_FAC_WINDOW_SIZE 0x43
-#define X25_MAX_FAC_LEN 20 /* Plenty to spare */
+#define X25_MAX_FAC_LEN 60
#define X25_MAX_CUD_LEN 128
+#define X25_FAC_CALLING_AE 0xCB
+#define X25_FAC_CALLED_AE 0xC9
+
+#define X25_MARKER 0x00
+#define X25_DTE_SERVICES 0x0F
+#define X25_MAX_AE_LEN 32
+
/**
* struct x25_route - x25 routing entry
* @node - entry in x25_list_lock
@@ -148,6 +155,7 @@ struct x25_sock {
struct timer_list timer;
struct x25_causediag causediag;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
struct x25_calluserdata calluserdata;
unsigned long vc_facil_mask; /* inc_call facilities mask */
};
@@ -180,9 +188,9 @@ extern void x25_establish_link(struct x2
extern void x25_terminate_link(struct x25_neigh *);
/* x25_facilities.c */
-extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities *, unsigned long *);
-extern int x25_create_facilities(unsigned char *, struct x25_facilities *, unsigned long);
-extern int x25_negotiate_facilities(struct sk_buff *, struct sock *, struct x25_facilities *);
+extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities *, struct x25_dte_facilities *, unsigned long *);
+extern int x25_create_facilities(unsigned char *, struct x25_facilities *, struct x25_dte_facilities *, unsigned long);
+extern int x25_negotiate_facilities(struct sk_buff *, struct sock *, struct x25_facilities *, struct x25_dte_facilities *);
extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
/* x25_in.c */
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/af_x25.c linux-2.6.16-rc3/net/x25/af_x25.c
--- linux-2.6.16-rc3-vanilla/net/x25/af_x25.c 2006-02-15 11:15:10.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/af_x25.c 2006-02-15 11:15:32.000000000 +1100
@@ -524,6 +524,13 @@ static int x25_create(struct socket *soc
x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE;
x25->facilities.throughput = X25_DEFAULT_THROUGHPUT;
x25->facilities.reverse = X25_DEFAULT_REVERSE;
+ x25->dte_facilities.calling_len = 0;
+ x25->dte_facilities.called_len = 0;
+ memset(x25->dte_facilities.called_ae, '\0',
+ sizeof(x25->dte_facilities.called_ae));
+ memset(x25->dte_facilities.calling_ae, '\0',
+ sizeof(x25->dte_facilities.calling_ae));
+
rc = 0;
out:
return rc;
@@ -560,6 +567,7 @@ static struct sock *x25_make_new(struct
x25->t2 = ox25->t2;
x25->facilities = ox25->facilities;
x25->qbitincl = ox25->qbitincl;
+ x25->dte_facilities = ox25->dte_facilities;
x25->cudmatchlength = ox25->cudmatchlength;
x25->accptapprv = ox25->accptapprv;
@@ -839,6 +847,7 @@ int x25_rx_call_request(struct sk_buff *
struct x25_sock *makex25;
struct x25_address source_addr, dest_addr;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
int len, rc;
/*
@@ -875,7 +884,8 @@ int x25_rx_call_request(struct sk_buff *
/*
* Try to reach a compromise on the requested facilities.
*/
- if ((len = x25_negotiate_facilities(skb, sk, &facilities)) == -1)
+ if ((len = x25_negotiate_facilities(skb, sk, &facilities,
+ &dte_facilities)) == -1)
goto out_sock_put;
/*
@@ -906,9 +916,12 @@ int x25_rx_call_request(struct sk_buff *
makex25->source_addr = source_addr;
makex25->neighbour = nb;
makex25->facilities = facilities;
+ makex25->dte_facilities= dte_facilities;
makex25->vc_facil_mask = x25_sk(sk)->vc_facil_mask;
/* ensure no reverse facil on accept */
makex25->vc_facil_mask &= ~X25_MASK_REVERSE;
+ /* ensure no calling address extension on accept */
+ makex25->vc_facil_mask &= ~X25_MASK_CALLING_AE;
makex25->cudmatchlength = x25_sk(sk)->cudmatchlength;
/* Normally all calls are accepted immediatly */
@@ -1315,6 +1328,34 @@ static int x25_ioctl(struct socket *sock
break;
}
+ case SIOCX25GDTEFACILITIES: {
+ rc = copy_to_user(argp, &x25->dte_facilities,
+ sizeof(x25->dte_facilities)) ? -EFAULT : 0;
+ break;
+ }
+
+ case SIOCX25SDTEFACILITIES: {
+ struct x25_dte_facilities dtefacs;
+ rc = -EFAULT;
+ if (copy_from_user(&dtefacs, argp, sizeof(dtefacs)))
+ break;
+ rc = -EINVAL;
+ if (sk->sk_state != TCP_LISTEN &&
+ sk->sk_state != TCP_CLOSE)
+ break;
+ if (dtefacs.calling_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.calling_ae == NULL)
+ break;
+ if (dtefacs.called_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.called_ae == NULL)
+ break;
+ x25->dte_facilities = dtefacs;
+ rc = 0;
+ break;
+ }
+
case SIOCX25GCALLUSERDATA: {
struct x25_calluserdata cud = x25->calluserdata;
rc = copy_to_user(argp, &cud,
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c linux-2.6.16-rc3/net/x25/x25_facilities.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c 2006-02-15 10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_facilities.c 2006-02-15 11:15:32.000000000 +1100
@@ -28,11 +28,12 @@
#include <net/x25.h>
/*
- * Parse a set of facilities into the facilities structure. Unrecognised
+ * Parse a set of facilities into the facilities structures. Unrecognised
* facilities are written to the debug log file.
*/
int x25_parse_facilities(struct sk_buff *skb,
struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
unsigned long *vc_fac_mask)
{
unsigned char *p = skb->data;
@@ -40,6 +41,16 @@ int x25_parse_facilities(struct sk_buff
*vc_fac_mask = 0;
+ /* The kernel knows which facilities were set on an incoming call
+ * but currently this information is not available to userspace.
+ * Here we give userspace who read incoming call facilities
+ * 0 length to indicate it wasn't set.
+ */
+ dte_facs->calling_len = 0;
+ dte_facs->called_len = 0;
+ memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae));
+ memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae));
+
while (len > 0) {
switch (*p & X25_FAC_CLASS_MASK) {
case X25_FAC_CLASS_A:
@@ -74,6 +85,10 @@ int x25_parse_facilities(struct sk_buff
facilities->throughput = p[1];
*vc_fac_mask |= X25_MASK_THROUGHPUT;
break;
+
+ case X25_MARKER:
+ break;
+
default:
printk(KERN_DEBUG "X.25: unknown facility "
"%02X, value %02X\n",
@@ -112,9 +127,30 @@ int x25_parse_facilities(struct sk_buff
len -= 4;
break;
case X25_FAC_CLASS_D:
- printk(KERN_DEBUG "X.25: unknown facility %02X, "
- "length %d, values %02X, %02X, %02X, %02X\n",
- p[0], p[1], p[2], p[3], p[4], p[5]);
+ switch (*p) {
+ case X25_FAC_CALLING_AE:
+ if (p[1] > 33)
+ break;
+ dte_facs->calling_len = p[2];
+ memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLING_AE;
+ break;
+
+ case X25_FAC_CALLED_AE:
+ if (p[1] > 33)
+ break;
+ dte_facs->called_len = p[2];
+ memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLED_AE;
+ break;
+
+ default:
+ printk(KERN_DEBUG "X.25: unknown facility %02X,"
+ "length %d, values %02X, %02X, %02X, %02X\n",
+ p[0], p[1], p[2], p[3], p[4], p[5]);
+ break;
+ }
+
len -= p[1] + 2;
p += p[1] + 2;
break;
@@ -129,6 +165,7 @@ int x25_parse_facilities(struct sk_buff
*/
int x25_create_facilities(unsigned char *buffer,
struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
unsigned long facil_mask)
{
unsigned char *p = buffer + 1;
@@ -168,6 +205,34 @@ int x25_create_facilities(unsigned char
*p++ = facilities->winsize_out ? : facilities->winsize_in;
}
+ if ((facil_mask & X25_MASK_CALLING_AE) ||
+ (facil_mask & X25_MASK_CALLED_AE)) {
+ *p++ = X25_MARKER;
+ *p++ = X25_DTE_SERVICES;
+ }
+
+ if (dte_facs->calling_len && (facil_mask & X25_MASK_CALLING_AE)) {
+ unsigned bytecount = (dte_facs->calling_len % 2) ?
+ dte_facs->calling_len / 2 + 1 :
+ dte_facs->calling_len / 2;
+ *p++ = X25_FAC_CALLING_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->calling_len;
+ memcpy(p, dte_facs->calling_ae, bytecount);
+ p+=bytecount;
+ }
+
+ if (dte_facs->called_len && (facil_mask & X25_MASK_CALLED_AE)) {
+ unsigned bytecount = (dte_facs->called_len % 2) ?
+ dte_facs->called_len / 2 + 1 :
+ dte_facs->called_len / 2;
+ *p++ = X25_FAC_CALLED_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->called_len;
+ memcpy(p, dte_facs->called_ae, bytecount);
+ p+=bytecount;
+ }
+
len = p - buffer;
buffer[0] = len - 1;
@@ -180,7 +245,8 @@ int x25_create_facilities(unsigned char
* The only real problem is with reverse charging.
*/
int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
- struct x25_facilities *new)
+ struct x25_facilities *new,
+ struct x25_dte_facilities *dte)
{
struct x25_sock *x25 = x25_sk(sk);
struct x25_facilities *ours = &x25->facilities;
@@ -190,7 +256,7 @@ int x25_negotiate_facilities(struct sk_b
memset(&theirs, 0, sizeof(theirs));
memcpy(new, ours, sizeof(*new));
- len = x25_parse_facilities(skb, &theirs, &x25->vc_facil_mask);
+ len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask);
/*
* They want reverse charging, we won't accept it.
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_in.c linux-2.6.16-rc3/net/x25/x25_in.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_in.c 2006-02-15 10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_in.c 2006-02-15 11:15:32.000000000 +1100
@@ -106,7 +106,8 @@ static int x25_state1_machine(struct soc
skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr));
skb_pull(skb,
x25_parse_facilities(skb, &x25->facilities,
- &x25->vc_facil_mask));
+ &x25->dte_facilities,
+ &x25->vc_facil_mask));
/*
* Copy any Call User Data.
*/
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c linux-2.6.16-rc3/net/x25/x25_subr.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c 2006-02-15 10:58:03.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_subr.c 2006-02-15 11:15:32.000000000 +1100
@@ -191,7 +191,8 @@ void x25_write_internal(struct sock *sk,
memcpy(dptr, addresses, len);
len = x25_create_facilities(facilities,
&x25->facilities,
- x25->neighbour->global_facil_mask);
+ &x25->dte_facilities,
+ x25->neighbour->global_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
dptr = skb_put(skb, x25->calluserdata.cudlength);
@@ -206,6 +207,7 @@ void x25_write_internal(struct sock *sk,
*dptr++ = 0x00; /* Address lengths */
len = x25_create_facilities(facilities,
&x25->facilities,
+ &x25->dte_facilities,
x25->vc_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
2006-02-15 22:35 ` Arnaldo Carvalho de Melo
@ 2006-02-16 5:40 ` Shaun Pereira
0 siblings, 0 replies; 7+ messages in thread
From: Shaun Pereira @ 2006-02-16 5:40 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: netdev, linux-kenel, x25 maintainer, David S. Miller,
Arnd Bergmann, Andre Hendry
Thanks for that Aranaldo
I have corrected this so as to be compliant with OSI Network services
for DTE facilities and rebuilt and retested the patches
Corrected patches follow.
On Wed, 2006-02-15 at 20:35 -0200, Arnaldo Carvalho de Melo wrote:
> On 2/15/06, Shaun Pereira <spereira@tusc.com.au> wrote:
>
> > + switch (*p) {
> > + case X25_FAC_CALLING_AE:
> > + if (p[1] > 33)
> > + break;
> > + dte_facs->calling_len = p[2];
> > + memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
> > + *vc_fac_mask |= X25_MASK_CALLING_AE;
> > + break;
>
> Can this '33' magic number be replaced with a define or sizeof(something)?
>
> - Arnaldo
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
@ 2006-02-16 5:46 Shaun Pereira
2006-02-16 14:18 ` Ingo Oeser
0 siblings, 1 reply; 7+ messages in thread
From: Shaun Pereira @ 2006-02-16 5:46 UTC (permalink / raw)
To: linux-kenel, netdev, David S. Miller
removed magic number 33 as suggested by Arnaldo
32 bit modular socket ioctl emulation for 64 bit kernel
This patch is a re-submit of an earlier patch submitted by Andrew Hendry
that did not make it into the Linux Kernel. Here is some more information
about this patch.
This patch allows use of the optional user facility to insert ITU-T
(http://www.itu.int/ITU-T/) specified DTE facilities in call set-up x25 packets.
This feature is optional; no facilities will be added if the ioctl is not used,
and call setup packet remains the same as before.
If the ioctls provided by the patch are used, then a facility marker will be
added to the x25 packet header so that the called dte address extension
facility can be differentiated from other types of facilities (as described
in the ITU-T X.25 recommendation) that are also allowed in the x25 packet header.
Facility markers are made up of two octets, and may be present in the x25 packet
headers of call-request, incoming call, call accepted, clear request,
and clear indication packets. The first of the two octets represents the
facility code field and is set to zero by this patch. The second octet of the
marker represents the facility parameter field and is set to 0x0F because the
marker will be inserted before ITU-T type DTE facilities.
Since according to ITU-T X.25 Recommendation X.25(10/96)- 7.1 "All networks
will support the facility markers with a facility parameter field set to
all ones or to 00001111", therefore this patch should work with all x.25
networks.
While there are many ITU-T DTE facilities, this patch implements only the
called and calling address extension, with placeholders in the x25_dte_facilities
structure for the rest of the facilities.
Testing
This patch was tested using a cisco xot router connected on its serial ports
to an X.25 network, and on its lan ports to a host running an xotd daemon.
It is also possible to test this patch using an xotd daemon and an x25tap patch,
where the xotd daemons work back-to-back without actually using an x.25 network.
See www.fyonne.net for details on how to do this.
Signed-off-by:Shaun Pereira <spereira@tusc.com.au>
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/linux/x25.h linux-2.6.16-rc3/include/linux/x25.h
--- linux-2.6.16-rc3-vanilla/include/linux/x25.h 2006-02-16 15:26:19.000000000 +1100
+++ linux-2.6.16-rc3/include/linux/x25.h 2006-02-16 15:31:50.000000000 +1100
@@ -11,6 +11,8 @@
#ifndef X25_KERNEL_H
#define X25_KERNEL_H
+#include <linux/types.h>
+
#define SIOCX25GSUBSCRIP (SIOCPROTOPRIVATE + 0)
#define SIOCX25SSUBSCRIP (SIOCPROTOPRIVATE + 1)
#define SIOCX25GFACILITIES (SIOCPROTOPRIVATE + 2)
@@ -21,6 +23,8 @@
#define SIOCX25SCUDMATCHLEN (SIOCPROTOPRIVATE + 7)
#define SIOCX25CALLACCPTAPPRV (SIOCPROTOPRIVATE + 8)
#define SIOCX25SENDCALLACCPT (SIOCPROTOPRIVATE + 9)
+#define SIOCX25GDTEFACILITIES (SIOCPROTOPRIVATE + 10)
+#define SIOCX25SDTEFACILITIES (SIOCPROTOPRIVATE + 11)
/*
* Values for {get,set}sockopt.
@@ -77,6 +81,8 @@ struct x25_subscrip_struct {
#define X25_MASK_PACKET_SIZE 0x04
#define X25_MASK_WINDOW_SIZE 0x08
+#define X25_MASK_CALLING_AE 0x10
+#define X25_MASK_CALLED_AE 0x20
/*
@@ -99,6 +105,26 @@ struct x25_facilities {
};
/*
+* ITU DTE facilities
+* Only the called and calling address
+* extension are currently implemented.
+* The rest are in place to avoid the struct
+* changing size if someone needs them later
+*/
+
+struct x25_dte_facilities {
+ __u16 delay_cumul;
+ __u16 delay_target;
+ __u16 delay_max;
+ __u8 min_throughput;
+ __u8 expedited;
+ __u8 calling_len;
+ __u8 called_len;
+ __u8 calling_ae[20];
+ __u8 called_ae[20];
+};
+
+/*
* Call User Data structure.
*/
struct x25_calluserdata {
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/net/x25.h linux-2.6.16-rc3/include/net/x25.h
--- linux-2.6.16-rc3-vanilla/include/net/x25.h 2006-02-16 15:26:19.000000000 +1100
+++ linux-2.6.16-rc3/include/net/x25.h 2006-02-16 15:31:50.000000000 +1100
@@ -101,9 +101,17 @@ enum {
#define X25_FAC_PACKET_SIZE 0x42
#define X25_FAC_WINDOW_SIZE 0x43
-#define X25_MAX_FAC_LEN 20 /* Plenty to spare */
+#define X25_MAX_FAC_LEN 60
#define X25_MAX_CUD_LEN 128
+#define X25_FAC_CALLING_AE 0xCB
+#define X25_FAC_CALLED_AE 0xC9
+
+#define X25_MARKER 0x00
+#define X25_DTE_SERVICES 0x0F
+#define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
+#define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
+
/**
* struct x25_route - x25 routing entry
* @node - entry in x25_list_lock
@@ -148,6 +156,7 @@ struct x25_sock {
struct timer_list timer;
struct x25_causediag causediag;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
struct x25_calluserdata calluserdata;
unsigned long vc_facil_mask; /* inc_call facilities mask */
};
@@ -180,9 +189,9 @@ extern void x25_establish_link(struct x2
extern void x25_terminate_link(struct x25_neigh *);
/* x25_facilities.c */
-extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities *, unsigned long *);
-extern int x25_create_facilities(unsigned char *, struct x25_facilities *, unsigned long);
-extern int x25_negotiate_facilities(struct sk_buff *, struct sock *, struct x25_facilities *);
+extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities *, struct x25_dte_facilities *, unsigned long *);
+extern int x25_create_facilities(unsigned char *, struct x25_facilities *, struct x25_dte_facilities *, unsigned long);
+extern int x25_negotiate_facilities(struct sk_buff *, struct sock *, struct x25_facilities *, struct x25_dte_facilities *);
extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
/* x25_in.c */
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/af_x25.c linux-2.6.16-rc3/net/x25/af_x25.c
--- linux-2.6.16-rc3-vanilla/net/x25/af_x25.c 2006-02-16 15:30:17.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/af_x25.c 2006-02-16 15:31:50.000000000 +1100
@@ -524,6 +524,13 @@ static int x25_create(struct socket *soc
x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE;
x25->facilities.throughput = X25_DEFAULT_THROUGHPUT;
x25->facilities.reverse = X25_DEFAULT_REVERSE;
+ x25->dte_facilities.calling_len = 0;
+ x25->dte_facilities.called_len = 0;
+ memset(x25->dte_facilities.called_ae, '\0',
+ sizeof(x25->dte_facilities.called_ae));
+ memset(x25->dte_facilities.calling_ae, '\0',
+ sizeof(x25->dte_facilities.calling_ae));
+
rc = 0;
out:
return rc;
@@ -560,6 +567,7 @@ static struct sock *x25_make_new(struct
x25->t2 = ox25->t2;
x25->facilities = ox25->facilities;
x25->qbitincl = ox25->qbitincl;
+ x25->dte_facilities = ox25->dte_facilities;
x25->cudmatchlength = ox25->cudmatchlength;
x25->accptapprv = ox25->accptapprv;
@@ -839,6 +847,7 @@ int x25_rx_call_request(struct sk_buff *
struct x25_sock *makex25;
struct x25_address source_addr, dest_addr;
struct x25_facilities facilities;
+ struct x25_dte_facilities dte_facilities;
int len, rc;
/*
@@ -875,7 +884,8 @@ int x25_rx_call_request(struct sk_buff *
/*
* Try to reach a compromise on the requested facilities.
*/
- if ((len = x25_negotiate_facilities(skb, sk, &facilities)) == -1)
+ if ((len = x25_negotiate_facilities(skb, sk, &facilities,
+ &dte_facilities)) == -1)
goto out_sock_put;
/*
@@ -906,9 +916,12 @@ int x25_rx_call_request(struct sk_buff *
makex25->source_addr = source_addr;
makex25->neighbour = nb;
makex25->facilities = facilities;
+ makex25->dte_facilities= dte_facilities;
makex25->vc_facil_mask = x25_sk(sk)->vc_facil_mask;
/* ensure no reverse facil on accept */
makex25->vc_facil_mask &= ~X25_MASK_REVERSE;
+ /* ensure no calling address extension on accept */
+ makex25->vc_facil_mask &= ~X25_MASK_CALLING_AE;
makex25->cudmatchlength = x25_sk(sk)->cudmatchlength;
/* Normally all calls are accepted immediatly */
@@ -1315,6 +1328,34 @@ static int x25_ioctl(struct socket *sock
break;
}
+ case SIOCX25GDTEFACILITIES: {
+ rc = copy_to_user(argp, &x25->dte_facilities,
+ sizeof(x25->dte_facilities)) ? -EFAULT : 0;
+ break;
+ }
+
+ case SIOCX25SDTEFACILITIES: {
+ struct x25_dte_facilities dtefacs;
+ rc = -EFAULT;
+ if (copy_from_user(&dtefacs, argp, sizeof(dtefacs)))
+ break;
+ rc = -EINVAL;
+ if (sk->sk_state != TCP_LISTEN &&
+ sk->sk_state != TCP_CLOSE)
+ break;
+ if (dtefacs.calling_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.calling_ae == NULL)
+ break;
+ if (dtefacs.called_len > X25_MAX_AE_LEN)
+ break;
+ if (dtefacs.called_ae == NULL)
+ break;
+ x25->dte_facilities = dtefacs;
+ rc = 0;
+ break;
+ }
+
case SIOCX25GCALLUSERDATA: {
struct x25_calluserdata cud = x25->calluserdata;
rc = copy_to_user(argp, &cud,
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c linux-2.6.16-rc3/net/x25/x25_facilities.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c 2006-02-16 15:26:25.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_facilities.c 2006-02-16 15:31:50.000000000 +1100
@@ -28,18 +28,29 @@
#include <net/x25.h>
/*
- * Parse a set of facilities into the facilities structure. Unrecognised
+ * Parse a set of facilities into the facilities structures. Unrecognised
* facilities are written to the debug log file.
*/
int x25_parse_facilities(struct sk_buff *skb,
- struct x25_facilities *facilities,
- unsigned long *vc_fac_mask)
+ struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
+ unsigned long *vc_fac_mask)
{
unsigned char *p = skb->data;
unsigned int len = *p++;
*vc_fac_mask = 0;
+ /* The kernel knows which facilities were set on an incoming call
+ * but currently this information is not available to userspace.
+ * Here we give userspace who read incoming call facilities
+ * 0 length to indicate it wasn't set.
+ */
+ dte_facs->calling_len = 0;
+ dte_facs->called_len = 0;
+ memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae));
+ memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae));
+
while (len > 0) {
switch (*p & X25_FAC_CLASS_MASK) {
case X25_FAC_CLASS_A:
@@ -74,6 +85,10 @@ int x25_parse_facilities(struct sk_buff
facilities->throughput = p[1];
*vc_fac_mask |= X25_MASK_THROUGHPUT;
break;
+
+ case X25_MARKER:
+ break;
+
default:
printk(KERN_DEBUG "X.25: unknown facility "
"%02X, value %02X\n",
@@ -112,9 +127,30 @@ int x25_parse_facilities(struct sk_buff
len -= 4;
break;
case X25_FAC_CLASS_D:
- printk(KERN_DEBUG "X.25: unknown facility %02X, "
- "length %d, values %02X, %02X, %02X, %02X\n",
- p[0], p[1], p[2], p[3], p[4], p[5]);
+ switch (*p) {
+ case X25_FAC_CALLING_AE:
+ if (p[1] > X25_MAX_DTE_FACIL_LEN)
+ break;
+ dte_facs->calling_len = p[2];
+ memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLING_AE;
+ break;
+
+ case X25_FAC_CALLED_AE:
+ if (p[1] > X25_MAX_DTE_FACIL_LEN)
+ break;
+ dte_facs->called_len = p[2];
+ memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
+ *vc_fac_mask |= X25_MASK_CALLED_AE;
+ break;
+
+ default:
+ printk(KERN_DEBUG "X.25: unknown facility %02X,"
+ "length %d, values %02X, %02X, %02X, %02X\n",
+ p[0], p[1], p[2], p[3], p[4], p[5]);
+ break;
+ }
+
len -= p[1] + 2;
p += p[1] + 2;
break;
@@ -128,8 +164,9 @@ int x25_parse_facilities(struct sk_buff
* Create a set of facilities.
*/
int x25_create_facilities(unsigned char *buffer,
- struct x25_facilities *facilities,
- unsigned long facil_mask)
+ struct x25_facilities *facilities,
+ struct x25_dte_facilities *dte_facs,
+ unsigned long facil_mask)
{
unsigned char *p = buffer + 1;
int len;
@@ -168,6 +205,34 @@ int x25_create_facilities(unsigned char
*p++ = facilities->winsize_out ? : facilities->winsize_in;
}
+ if ((facil_mask & X25_MASK_CALLING_AE) ||
+ (facil_mask & X25_MASK_CALLED_AE)) {
+ *p++ = X25_MARKER;
+ *p++ = X25_DTE_SERVICES;
+ }
+
+ if (dte_facs->calling_len && (facil_mask & X25_MASK_CALLING_AE)) {
+ unsigned bytecount = (dte_facs->calling_len % 2) ?
+ dte_facs->calling_len / 2 + 1 :
+ dte_facs->calling_len / 2;
+ *p++ = X25_FAC_CALLING_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->calling_len;
+ memcpy(p, dte_facs->calling_ae, bytecount);
+ p+=bytecount;
+ }
+
+ if (dte_facs->called_len && (facil_mask & X25_MASK_CALLED_AE)) {
+ unsigned bytecount = (dte_facs->called_len % 2) ?
+ dte_facs->called_len / 2 + 1 :
+ dte_facs->called_len / 2;
+ *p++ = X25_FAC_CALLED_AE;
+ *p++ = 1 + bytecount;
+ *p++ = dte_facs->called_len;
+ memcpy(p, dte_facs->called_ae, bytecount);
+ p+=bytecount;
+ }
+
len = p - buffer;
buffer[0] = len - 1;
@@ -180,7 +245,8 @@ int x25_create_facilities(unsigned char
* The only real problem is with reverse charging.
*/
int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
- struct x25_facilities *new)
+ struct x25_facilities *new,
+ struct x25_dte_facilities *dte)
{
struct x25_sock *x25 = x25_sk(sk);
struct x25_facilities *ours = &x25->facilities;
@@ -190,7 +256,7 @@ int x25_negotiate_facilities(struct sk_b
memset(&theirs, 0, sizeof(theirs));
memcpy(new, ours, sizeof(*new));
- len = x25_parse_facilities(skb, &theirs, &x25->vc_facil_mask);
+ len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask);
/*
* They want reverse charging, we won't accept it.
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_in.c linux-2.6.16-rc3/net/x25/x25_in.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_in.c 2006-02-16 15:26:25.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_in.c 2006-02-16 15:31:50.000000000 +1100
@@ -106,7 +106,8 @@ static int x25_state1_machine(struct soc
skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr));
skb_pull(skb,
x25_parse_facilities(skb, &x25->facilities,
- &x25->vc_facil_mask));
+ &x25->dte_facilities,
+ &x25->vc_facil_mask));
/*
* Copy any Call User Data.
*/
diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c linux-2.6.16-rc3/net/x25/x25_subr.c
--- linux-2.6.16-rc3-vanilla/net/x25/x25_subr.c 2006-02-16 15:26:25.000000000 +1100
+++ linux-2.6.16-rc3/net/x25/x25_subr.c 2006-02-16 15:31:50.000000000 +1100
@@ -191,7 +191,8 @@ void x25_write_internal(struct sock *sk,
memcpy(dptr, addresses, len);
len = x25_create_facilities(facilities,
&x25->facilities,
- x25->neighbour->global_facil_mask);
+ &x25->dte_facilities,
+ x25->neighbour->global_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
dptr = skb_put(skb, x25->calluserdata.cudlength);
@@ -206,6 +207,7 @@ void x25_write_internal(struct sock *sk,
*dptr++ = 0x00; /* Address lengths */
len = x25_create_facilities(facilities,
&x25->facilities,
+ &x25->dte_facilities,
x25->vc_facil_mask);
dptr = skb_put(skb, len);
memcpy(dptr, facilities, len);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
2006-02-16 5:46 [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel Shaun Pereira
@ 2006-02-16 14:18 ` Ingo Oeser
2006-02-16 22:51 ` Shaun Pereira
0 siblings, 1 reply; 7+ messages in thread
From: Ingo Oeser @ 2006-02-16 14:18 UTC (permalink / raw)
To: spereira; +Cc: linux-kenel, netdev, David S. Miller
Shaun Pereira wrote:
> removed magic number 33 as suggested by Arnaldo
But are you sure, you use the right substitute for it?
> struct x25_calluserdata {
> diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/net/x25.h linux-2.6.16-rc3/include/net/x25.h
> --- linux-2.6.16-rc3-vanilla/include/net/x25.h 2006-02-16 15:26:19.000000000 +1100
> +++ linux-2.6.16-rc3/include/net/x25.h 2006-02-16 15:31:50.000000000 +1100
> @@ -101,9 +101,17 @@ enum {
> #define X25_FAC_PACKET_SIZE 0x42
> #define X25_FAC_WINDOW_SIZE 0x43
>
> -#define X25_MAX_FAC_LEN 20 /* Plenty to spare */
> +#define X25_MAX_FAC_LEN 60
> #define X25_MAX_CUD_LEN 128
>
> +#define X25_FAC_CALLING_AE 0xCB
> +#define X25_FAC_CALLED_AE 0xC9
> +
> +#define X25_MARKER 0x00
> +#define X25_DTE_SERVICES 0x0F
> +#define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
> +#define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
Are you sure that you don't mean 0x21 (== 33) here?
> diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c linux-2.6.16-rc3/net/x25/x25_facilities.c
> --- linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c 2006-02-16 15:26:25.000000000 +1100
> +++ linux-2.6.16-rc3/net/x25/x25_facilities.c 2006-02-16 15:31:50.000000000 +1100
> @@ -112,9 +127,30 @@ int x25_parse_facilities(struct sk_buff
> len -= 4;
> break;
> case X25_FAC_CLASS_D:
> - printk(KERN_DEBUG "X.25: unknown facility %02X, "
> - "length %d, values %02X, %02X, %02X, %02X\n",
> - p[0], p[1], p[2], p[3], p[4], p[5]);
> + switch (*p) {
> + case X25_FAC_CALLING_AE:
> + if (p[1] > X25_MAX_DTE_FACIL_LEN)
Because the magic number 33 was here before ...
> + break;
> + dte_facs->calling_len = p[2];
> + memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
> + *vc_fac_mask |= X25_MASK_CALLING_AE;
> + break;
> +
> + case X25_FAC_CALLED_AE:
> + if (p[1] > X25_MAX_DTE_FACIL_LEN)
...and here
> + break;
> + dte_facs->called_len = p[2];
> + memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
> + *vc_fac_mask |= X25_MASK_CALLED_AE;
> + break;
> +
> + default:
> + printk(KERN_DEBUG "X.25: unknown facility %02X,"
> + "length %d, values %02X, %02X, %02X, %02X\n",
> + p[0], p[1], p[2], p[3], p[4], p[5]);
> + break;
> + }
> +
> len -= p[1] + 2;
> p += p[1] + 2;
> break;
Regards
Ingo Oeser
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel
2006-02-16 14:18 ` Ingo Oeser
@ 2006-02-16 22:51 ` Shaun Pereira
0 siblings, 0 replies; 7+ messages in thread
From: Shaun Pereira @ 2006-02-16 22:51 UTC (permalink / raw)
To: Ingo Oeser; +Cc: linux-kenel, netdev, David S. Miller
Thank for reviewing the patch Ingo.
There was a mistake the first time round, lucky for me Arnaldo's comment
about the magic number helped me spot it. When ITU-T DTE facilities are
added to the X.25 header packet the length field has to contain n + 1
bytes where n is the number of bytes needed to hold the calling(or
called address) extension.
The kernel used to check that the maximum number of bytes/allowed-length
is 33. However as I understand the X.25 recommendation for
ITU-T specified DTE facilities to support OSI network services, the
value of n can be a maximum of 20 bytes. This makes the allowable
length 21. By co-incidence 0x21 turned out to be 33 bytes. But I meant
21 bytes. The other decimal value of 40 is the maximum number of semi-
octets in the calling address extension. (Therefore 20 octets + 1 in the
length field).
Now I just have to correct my other mistake .. all these patches have
the same subject...
Regards
Shaun
On Thu, 2006-02-16 at 15:18 +0100, Ingo Oeser wrote:
> Shaun Pereira wrote:
> > removed magic number 33 as suggested by Arnaldo
>
> But are you sure, you use the right substitute for it?
>
> > struct x25_calluserdata {
> > diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/include/net/x25.h linux-2.6.16-rc3/include/net/x25.h
> > --- linux-2.6.16-rc3-vanilla/include/net/x25.h 2006-02-16 15:26:19.000000000 +1100
> > +++ linux-2.6.16-rc3/include/net/x25.h 2006-02-16 15:31:50.000000000 +1100
> > @@ -101,9 +101,17 @@ enum {
> > #define X25_FAC_PACKET_SIZE 0x42
> > #define X25_FAC_WINDOW_SIZE 0x43
> >
> > -#define X25_MAX_FAC_LEN 20 /* Plenty to spare */
> > +#define X25_MAX_FAC_LEN 60
> > #define X25_MAX_CUD_LEN 128
> >
> > +#define X25_FAC_CALLING_AE 0xCB
> > +#define X25_FAC_CALLED_AE 0xC9
> > +
> > +#define X25_MARKER 0x00
> > +#define X25_DTE_SERVICES 0x0F
> > +#define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
> > +#define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
>
> Are you sure that you don't mean 0x21 (== 33) here?
>
> > diff -uprN -X dontdiff linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c linux-2.6.16-rc3/net/x25/x25_facilities.c
> > --- linux-2.6.16-rc3-vanilla/net/x25/x25_facilities.c 2006-02-16 15:26:25.000000000 +1100
> > +++ linux-2.6.16-rc3/net/x25/x25_facilities.c 2006-02-16 15:31:50.000000000 +1100
> > @@ -112,9 +127,30 @@ int x25_parse_facilities(struct sk_buff
> > len -= 4;
> > break;
> > case X25_FAC_CLASS_D:
> > - printk(KERN_DEBUG "X.25: unknown facility %02X, "
> > - "length %d, values %02X, %02X, %02X, %02X\n",
> > - p[0], p[1], p[2], p[3], p[4], p[5]);
> > + switch (*p) {
> > + case X25_FAC_CALLING_AE:
> > + if (p[1] > X25_MAX_DTE_FACIL_LEN)
>
> Because the magic number 33 was here before ...
>
> > + break;
> > + dte_facs->calling_len = p[2];
> > + memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
> > + *vc_fac_mask |= X25_MASK_CALLING_AE;
> > + break;
> > +
> > + case X25_FAC_CALLED_AE:
> > + if (p[1] > X25_MAX_DTE_FACIL_LEN)
>
> ...and here
>
> > + break;
> > + dte_facs->called_len = p[2];
> > + memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
> > + *vc_fac_mask |= X25_MASK_CALLED_AE;
> > + break;
> > +
> > + default:
> > + printk(KERN_DEBUG "X.25: unknown facility %02X,"
> > + "length %d, values %02X, %02X, %02X, %02X\n",
> > + p[0], p[1], p[2], p[3], p[4], p[5]);
> > + break;
> > + }
> > +
> > len -= p[1] + 2;
> > p += p[1] + 2;
> > break;
>
> Regards
>
> Ingo Oeser
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-02-16 22:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-16 5:46 [PATCH 5/6] x25: Allow 32 bit socket ioctl in 64 bit kernel Shaun Pereira
2006-02-16 14:18 ` Ingo Oeser
2006-02-16 22:51 ` Shaun Pereira
-- strict thread matches above, loose matches on Subject: below --
2006-02-15 22:41 Shaun Pereira
2006-02-15 22:22 Shaun Pereira
2006-02-15 22:35 ` Arnaldo Carvalho de Melo
2006-02-16 5:40 ` Shaun Pereira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).