Commit 7b34e449 authored by Justin Iurman's avatar Justin Iurman Committed by David S. Miller

ipv6: ioam: Prerequisite patch for ioam6_iptunnel

This prerequisite patch provides some minor edits (alignments, renames) and a
minor modification inside a function to facilitate the next patch by using
existing nla_* functions.
Signed-off-by: default avatarJustin Iurman <justin.iurman@uliege.be>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52d03786
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/net.h> #include <linux/net.h>
#include <linux/netlink.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/ioam6.h> #include <linux/ioam6.h>
#include <linux/ioam6_iptunnel.h> #include <linux/ioam6_iptunnel.h>
...@@ -17,15 +16,16 @@ ...@@ -17,15 +16,16 @@
#include <net/sock.h> #include <net/sock.h>
#include <net/lwtunnel.h> #include <net/lwtunnel.h>
#include <net/ioam6.h> #include <net/ioam6.h>
#include <net/netlink.h>
#define IOAM6_MASK_SHORT_FIELDS 0xff100000 #define IOAM6_MASK_SHORT_FIELDS 0xff100000
#define IOAM6_MASK_WIDE_FIELDS 0xe00000 #define IOAM6_MASK_WIDE_FIELDS 0xe00000
struct ioam6_lwt_encap { struct ioam6_lwt_encap {
struct ipv6_hopopt_hdr eh; struct ipv6_hopopt_hdr eh;
u8 pad[2]; /* 2-octet padding for 4n-alignment */ u8 pad[2]; /* 2-octet padding for 4n-alignment */
struct ioam6_hdr ioamh; struct ioam6_hdr ioamh;
struct ioam6_trace_hdr traceh; struct ioam6_trace_hdr traceh;
} __packed; } __packed;
struct ioam6_lwt { struct ioam6_lwt {
...@@ -42,7 +42,7 @@ static struct ioam6_lwt_encap *ioam6_lwt_info(struct lwtunnel_state *lwt) ...@@ -42,7 +42,7 @@ static struct ioam6_lwt_encap *ioam6_lwt_info(struct lwtunnel_state *lwt)
return &ioam6_lwt_state(lwt)->tuninfo; return &ioam6_lwt_state(lwt)->tuninfo;
} }
static struct ioam6_trace_hdr *ioam6_trace(struct lwtunnel_state *lwt) static struct ioam6_trace_hdr *ioam6_lwt_trace(struct lwtunnel_state *lwt)
{ {
return &(ioam6_lwt_state(lwt)->tuninfo.traceh); return &(ioam6_lwt_state(lwt)->tuninfo.traceh);
} }
...@@ -51,25 +51,6 @@ static const struct nla_policy ioam6_iptunnel_policy[IOAM6_IPTUNNEL_MAX + 1] = { ...@@ -51,25 +51,6 @@ static const struct nla_policy ioam6_iptunnel_policy[IOAM6_IPTUNNEL_MAX + 1] = {
[IOAM6_IPTUNNEL_TRACE] = NLA_POLICY_EXACT_LEN(sizeof(struct ioam6_trace_hdr)), [IOAM6_IPTUNNEL_TRACE] = NLA_POLICY_EXACT_LEN(sizeof(struct ioam6_trace_hdr)),
}; };
static int nla_put_ioam6_trace(struct sk_buff *skb, int attrtype,
struct ioam6_trace_hdr *trace)
{
struct ioam6_trace_hdr *data;
struct nlattr *nla;
int len;
len = sizeof(*trace);
nla = nla_reserve(skb, attrtype, len);
if (!nla)
return -EMSGSIZE;
data = nla_data(nla);
memcpy(data, trace, len);
return 0;
}
static bool ioam6_validate_trace_hdr(struct ioam6_trace_hdr *trace) static bool ioam6_validate_trace_hdr(struct ioam6_trace_hdr *trace)
{ {
u32 fields; u32 fields;
...@@ -231,36 +212,40 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -231,36 +212,40 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
static int ioam6_fill_encap_info(struct sk_buff *skb, static int ioam6_fill_encap_info(struct sk_buff *skb,
struct lwtunnel_state *lwtstate) struct lwtunnel_state *lwtstate)
{ {
struct ioam6_trace_hdr *trace = ioam6_trace(lwtstate); struct ioam6_trace_hdr *trace;
int err;
if (nla_put_ioam6_trace(skb, IOAM6_IPTUNNEL_TRACE, trace)) trace = ioam6_lwt_trace(lwtstate);
return -EMSGSIZE;
err = nla_put(skb, IOAM6_IPTUNNEL_TRACE, sizeof(*trace), trace);
if (err)
return err;
return 0; return 0;
} }
static int ioam6_encap_nlsize(struct lwtunnel_state *lwtstate) static int ioam6_encap_nlsize(struct lwtunnel_state *lwtstate)
{ {
struct ioam6_trace_hdr *trace = ioam6_trace(lwtstate); struct ioam6_trace_hdr *trace = ioam6_lwt_trace(lwtstate);
return nla_total_size(sizeof(*trace)); return nla_total_size(sizeof(*trace));
} }
static int ioam6_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b) static int ioam6_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b)
{ {
struct ioam6_trace_hdr *a_hdr = ioam6_trace(a); struct ioam6_trace_hdr *a_hdr = ioam6_lwt_trace(a);
struct ioam6_trace_hdr *b_hdr = ioam6_trace(b); struct ioam6_trace_hdr *b_hdr = ioam6_lwt_trace(b);
return (a_hdr->namespace_id != b_hdr->namespace_id); return (a_hdr->namespace_id != b_hdr->namespace_id);
} }
static const struct lwtunnel_encap_ops ioam6_iptun_ops = { static const struct lwtunnel_encap_ops ioam6_iptun_ops = {
.build_state = ioam6_build_state, .build_state = ioam6_build_state,
.output = ioam6_output, .output = ioam6_output,
.fill_encap = ioam6_fill_encap_info, .fill_encap = ioam6_fill_encap_info,
.get_encap_size = ioam6_encap_nlsize, .get_encap_size = ioam6_encap_nlsize,
.cmp_encap = ioam6_encap_cmp, .cmp_encap = ioam6_encap_cmp,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
int __init ioam6_iptunnel_init(void) int __init ioam6_iptunnel_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment