ipsec.c (7681a4f58fb9c338d6dfe1181607f84c793d77de) ipsec.c (6c48697955681ab1de1dfb7451c62898373b7e03)
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2018 Oracle and/or its affiliates. All rights reserved. */
3
4#include <crypto/aead.h>
5#include <linux/debugfs.h>
6#include <net/xfrm.h>
7
8#include "netdevsim.h"

--- 126 unchanged lines hidden (view full) ---

135 u16 sa_idx;
136 int ret;
137
138 dev = xs->xso.real_dev;
139 ns = netdev_priv(dev);
140 ipsec = &ns->ipsec;
141
142 if (xs->id.proto != IPPROTO_ESP && xs->id.proto != IPPROTO_AH) {
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2018 Oracle and/or its affiliates. All rights reserved. */
3
4#include <crypto/aead.h>
5#include <linux/debugfs.h>
6#include <net/xfrm.h>
7
8#include "netdevsim.h"

--- 126 unchanged lines hidden (view full) ---

135 u16 sa_idx;
136 int ret;
137
138 dev = xs->xso.real_dev;
139 ns = netdev_priv(dev);
140 ipsec = &ns->ipsec;
141
142 if (xs->id.proto != IPPROTO_ESP && xs->id.proto != IPPROTO_AH) {
143 netdev_err(dev, "Unsupported protocol 0x%04x for ipsec offload\n",
144 xs->id.proto);
143 NL_SET_ERR_MSG_MOD(extack, "Unsupported protocol for ipsec offload");
145 return -EINVAL;
146 }
147
148 if (xs->calg) {
144 return -EINVAL;
145 }
146
147 if (xs->calg) {
149 netdev_err(dev, "Compression offload not supported\n");
148 NL_SET_ERR_MSG_MOD(extack, "Compression offload not supported");
150 return -EINVAL;
151 }
152
153 if (xs->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
149 return -EINVAL;
150 }
151
152 if (xs->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
154 netdev_err(dev, "Unsupported ipsec offload type\n");
153 NL_SET_ERR_MSG_MOD(extack, "Unsupported ipsec offload type");
155 return -EINVAL;
156 }
157
158 /* find the first unused index */
159 ret = nsim_ipsec_find_empty_idx(ipsec);
160 if (ret < 0) {
154 return -EINVAL;
155 }
156
157 /* find the first unused index */
158 ret = nsim_ipsec_find_empty_idx(ipsec);
159 if (ret < 0) {
161 netdev_err(dev, "No space for SA in Rx table!\n");
160 NL_SET_ERR_MSG_MOD(extack, "No space for SA in Rx table!");
162 return ret;
163 }
164 sa_idx = (u16)ret;
165
166 memset(&sa, 0, sizeof(sa));
167 sa.used = true;
168 sa.xs = xs;
169
170 if (sa.xs->id.proto & IPPROTO_ESP)
171 sa.crypt = xs->ealg || xs->aead;
172
173 /* get the key and salt */
174 ret = nsim_ipsec_parse_proto_keys(xs, sa.key, &sa.salt);
175 if (ret) {
161 return ret;
162 }
163 sa_idx = (u16)ret;
164
165 memset(&sa, 0, sizeof(sa));
166 sa.used = true;
167 sa.xs = xs;
168
169 if (sa.xs->id.proto & IPPROTO_ESP)
170 sa.crypt = xs->ealg || xs->aead;
171
172 /* get the key and salt */
173 ret = nsim_ipsec_parse_proto_keys(xs, sa.key, &sa.salt);
174 if (ret) {
176 netdev_err(dev, "Failed to get key data for SA table\n");
175 NL_SET_ERR_MSG_MOD(extack, "Failed to get key data for SA table");
177 return ret;
178 }
179
180 if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) {
181 sa.rx = true;
182
183 if (xs->props.family == AF_INET6)
184 memcpy(sa.ipaddr, &xs->id.daddr.a6, 16);

--- 121 unchanged lines hidden ---
176 return ret;
177 }
178
179 if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) {
180 sa.rx = true;
181
182 if (xs->props.family == AF_INET6)
183 memcpy(sa.ipaddr, &xs->id.daddr.a6, 16);

--- 121 unchanged lines hidden ---