Projectname large_stringclasses 15
values | Filepath large_stringlengths 4 106 ⌀ | Function large_stringlengths 11 3.45k | Label list |
|---|---|---|---|
Linux Kernel | net/xfrm/xfrm_state.c |
struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark, u32 if_id,
xfrm_address_t *daddr,
xfrm_address_t *saddr,
unsigned short family, u8 mode, u8 proto,
... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
void xfrm_state_insert(struct xfrm_state *x) {
struct net *net = xs_net(x);
spin_lock_bh(&net->xfrm.xfrm_state_lock);
__xfrm_state_bump_genids(x);
__xfrm_state_insert(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | static void __xfrm6_sort(void **dst, void **src, int n,
int (*cmp)(const void *p), int maxclass) {
int count[XFRM_MAX_DEPTH] = {};
int class[XFRM_MAX_DEPTH];
int i;
for (i = 0; i < n; i++) {
int c = cmp(src[i]);
class[i] = c;
count[c]++;
}
for (i = 2; i < maxclass; i+... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | static int __xfrm6_tmpl_sort_cmp(const void *p) {
const struct xfrm_tmpl *v = p;
switch (v->mode) {
case XFRM_MODE_TRANSPORT:
return 1;
#if IS_ENABLED(CONFIG_IPV6_MIP6)
case XFRM_MODE_ROUTEOPTIMIZATION:
case XFRM_MODE_IN_TRIGGER:
return 2;
#endif
case XFRM_MODE_TUNNEL:
case XFRM_MODE_BEET:
re... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | static inline int __xfrm6_state_sort_cmp(const void *p) { return 5; } | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
void xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n,
unsigned short family) {
int i;
if (family == AF_INET6)
__xfrm6_sort((void **)dst, (void **)src, n, __xfrm6_tmpl_sort_cmp, 5);
else
for (i = 0; i < n; i++)
dst[i] = src[i];
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | int verify_spi_info(u8 proto, u32 min, u32 max,
struct netlink_ext_ack *extack) {
switch (proto) {
case IPPROTO_AH:
case IPPROTO_ESP:
break;
case IPPROTO_COMP:
if (max >= 0x10000) {
NL_SET_ERR_MSG(extack, "IPCOMP SPI must be <= 65535");
return -EINVAL;
}
break;
... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
int (*func)(struct xfrm_state *, int, void *), void *data) {
struct xfrm_state *state;
struct xfrm_state_walk *x;
int err = 0;
if (walk->seq != 0 && list_empty(&walk->all))
return 0;
spin_lock_bh(&net->xfrm.xfrm_stat... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto,
struct xfrm_address_filter *filter) {
INIT_LIST_HEAD(&walk->all);
walk->proto = proto;
walk->state = XFRM_STATE_DEAD;
walk->seq = 0;
walk->filter = filter;
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | int km_query(struct xfrm_state *x, struct xfrm_tmpl *t,
struct xfrm_policy *pol) {
int err = -EINVAL, acqret;
struct xfrm_mgr *km;
rcu_read_lock();
list_for_each_entry_rcu(km, &xfrm_km_list, list) {
acqret = km->acquire(x, t, pol);
if (!acqret)
err = acqret;
}
rcu_read_unlock();
... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport) {
int ret = 0;
if (x->mapping_maxage) {
if ((jiffies / HZ - x->new_mapping) > x->mapping_maxage ||
x->new_mapping_sport != sport) {
x->new_mapping_sport = sport;
x->new_mapping = jiffies / HZ;
ret = __km_n... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
struct xfrm_translator *xfrm_get_translator(void) {
struct xfrm_translator *xtr;
rcu_read_lock();
xtr = rcu_dereference(xfrm_translator);
if (unlikely(!xtr))
goto out;
if (!try_module_get(xtr->owner))
xtr = NULL;
out:
rcu_read_unlock();
return xtr;
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
int xfrm_unregister_translator(struct xfrm_translator *xtr) {
int err = 0;
spin_lock_bh(&xfrm_translator_lock);
if (likely(xfrm_translator != NULL)) {
if (rcu_access_pointer(xfrm_translator) != xtr)
err = -EINVAL;
else
RCU_INIT_POINTER(xfrm_translator, NULL);
}
spin_unlock_bh(&xfrm_trans... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
void xfrm_register_km(struct xfrm_mgr *km) {
spin_lock_bh(&xfrm_km_lock);
list_add_tail_rcu(&km->list, &xfrm_km_list);
spin_unlock_bh(&xfrm_km_lock);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo) {
int err = 0;
if (WARN_ON(afinfo->family >= NPROTO))
return -EAFNOSUPPORT;
spin_lock_bh(&xfrm_state_afinfo_lock);
if (unlikely(xfrm_state_afinfo[afinfo->family] != NULL))
err = -EEXIST;
else
rcu_assign_pointer(xfrm_state_afinfo[a... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | void xfrm_state_delete_tunnel(struct xfrm_state *x) {
if (x->tunnel) {
struct xfrm_state *t = x->tunnel;
if (atomic_read(&t->tunnel_users) == 2)
xfrm_state_delete(t);
atomic_dec(&t->tunnel_users);
xfrm_state_put_sync(t);
x->tunnel = NULL;
}
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c |
int xfrm_init_state(struct xfrm_state *x) {
int err;
err = __xfrm_init_state(x, true, false, NULL);
if (!err)
x->km.state = XFRM_STATE_VALID;
return err;
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_state.c | static void xfrm_audit_helper_sainfo(struct xfrm_state *x,
struct audit_buffer *audit_buf) {
struct xfrm_sec_ctx *ctx = x->security;
u32 spi = ntohl(x->id.spi);
if (ctx)
audit_log_format(audit_buf, " sec_alg=%u sec_doi=%u sec_obj=%s",
ctx->ctx_alg, ct... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_sysctl.c | int __net_init xfrm_sysctl_init(struct net *net) {
struct ctl_table *table;
__xfrm_sysctl_init(net);
table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL);
if (!table)
goto out_kmemdup;
table[0].data = &net->xfrm.sysctl_aevent_etime;
table[1].data = &net->xfrm.sysctl_aevent_rseqth;
table[2].da... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type,
struct netlink_ext_ack *extack) {
struct nlattr *rt = attrs[type];
struct xfrm_algo *algp;
if (!rt)
return 0;
algp = nla_data(rt);
if (nla_len(rt) < (int)xfrm_alg_len(algp)) {
NL_SET_ERR_MSG(extac... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int verify_aead(struct nlattr **attrs, struct netlink_ext_ack *extack) {
struct nlattr *rt = attrs[XFRMA_ALG_AEAD];
struct xfrm_algo_aead *algp;
if (!rt)
return 0;
algp = nla_data(rt);
if (nla_len(rt) < (int)aead_len(algp)) {
NL_SET_ERR_MSG(extack, "Invalid AEAD attribute length");
retur... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static inline int verify_replay(struct xfrm_usersa_info *p,
struct nlattr **attrs,
struct netlink_ext_ack *extack) {
struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
struct xfrm_replay_state_esn *rs;
if (!rt) {
if (p->flags & XFRM_STATE_ESN) {
... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props,
struct nlattr *rta,
struct netlink_ext_ack *extack) {
struct xfrm_algo_auth *p, *ualg;
struct xfrm_algo_desc *algo;
if (!rta)
return 0;
ualg = nla_data(rta);
algo = xfrm_aal... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static inline int
xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_esn,
struct nlattr *rp, struct netlink_ext_ack *extack) {
struct xfrm_replay_state_esn *up;
unsigned int ulen;
if (!replay_esn || !rp)
return 0;
up = nla_data(rp);
ulen = xfrm_replay_state_esn_len(up);
... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static inline unsigned int
xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx) {
unsigned int len = 0;
if (xfrm_ctx) {
len += sizeof(struct xfrm_user_sec_ctx);
len += xfrm_ctx->ctx_len;
}
return len;
} | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static void copy_from_user_state(struct xfrm_state *x,
struct xfrm_usersa_info *p) {
memcpy(&x->id, &p->id, sizeof(x->id));
memcpy(&x->sel, &p->sel, sizeof(x->sel));
memcpy(&x->lft, &p->lft, sizeof(x->lft));
x->props.mode = p->mode;
x->props.replay_window =
min_t(unsign... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs,
int update_esn) {
struct nlattr *rp = attrs[XFRMA_REPLAY_VAL];
struct nlattr *re = update_esn ? attrs[XFRMA_REPLAY_ESN_VAL] : NULL;
struct nlattr *lt = attrs[XFRMA_LTIME_VAL];
struct nlattr *et = att... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attrs, struct netlink_ext_ack *extack) {
struct net *net = sock_net(skb->sk);
struct xfrm_usersa_info *p = nlmsg_data(nlh);
struct xfrm_state *x;
int err;
struct km_event c;
err = verify_newsa_info(p, ... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int copy_sec_ctx(struct xfrm_sec_ctx *s, struct sk_buff *skb) {
struct xfrm_user_sec_ctx *uctx;
struct nlattr *attr;
int ctx_size = sizeof(*uctx) + s->ctx_len;
attr = nla_reserve(skb, XFRMA_SEC_CTX, ctx_size);
if (attr == NULL)
return -EMSGSIZE;
uctx = nla_data(attr);
uctx->exttype = XFRMA_S... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static bool xfrm_redact(void) {
return IS_ENABLED(CONFIG_SECURITY) &&
security_locked_down(LOCKDOWN_XFRM_SECRET);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
struct xfrm_state *x, u32 seq) {
struct xfrm_dump_info info;
struct sk_buff *skb;
int err;
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
if (!skb)
return ERR_PTR(-ENOMEM);
info.in_skb = in_s... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int verify_policy_type(u8 type, struct netlink_ext_ack *extack) {
switch (type) {
case XFRM_POLICY_TYPE_MAIN:
#ifdef CONFIG_XFRM_SUB_POLICY
case XFRM_POLICY_TYPE_SUB:
#endif
break;
default:
NL_SET_ERR_MSG(extack, "Invalid policy type");
return -EINVAL;
}
return 0;
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static void copy_to_user_policy(struct xfrm_policy *xp,
struct xfrm_userpolicy_info *p, int dir) {
memset(p, 0, sizeof(*p));
memcpy(&p->sel, &xp->selector, sizeof(p->sel));
memcpy(&p->lft, &xp->lft, sizeof(p->lft));
memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft));
p->priorit... | [
1,
1
] |
Linux Kernel | net/xfrm/xfrm_user.c | static struct xfrm_policy *
xfrm_policy_construct(struct net *net, struct xfrm_userpolicy_info *p,
struct nlattr **attrs, int *errp,
struct netlink_ext_ack *extack) {
struct xfrm_policy *xp = xfrm_policy_alloc(net, GFP_KERNEL);
int err;
if (!xp) {
*errp = -ENOMEM;
... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_dump_policy_done(struct netlink_callback *cb) {
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *)cb->args;
struct net *net = sock_net(cb->skb->sk);
xfrm_policy_walk_done(walk, net);
return 0;
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_dump_policy_start(struct netlink_callback *cb) {
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *)cb->args;
BUILD_BUG_ON(sizeof(*walk) > sizeof(cb->args));
xfrm_policy_walk_init(walk, XFRM_POLICY_TYPE_ANY);
return 0;
} | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attrs,
struct netlink_ext_ack *extack) {
struct sk_buff *r_skb;
struct nlmsghdr *r_nlh;
struct net *net = sock_net(skb->sk);
struct xfrm_userpolicy_default *r_up;
int... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attrs,
struct netlink_ext_ack *extack) {
struct net *net = sock_net(skb->sk);
struct km_event c;
u8 type = XFRM_POLICY_TYPE_MAIN;
int err;
err = copy_from_user_pol... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static int copy_from_user_migrate(struct xfrm_migrate *ma,
struct xfrm_kmaddress *k,
struct nlattr **attrs, int *num,
struct netlink_ext_ack *extack) {
struct nlattr *rt = attrs[XFRMA_MIGRATE];
struct xfrm_user_mig... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attrs,
struct netlink_ext_ack *extack) {
struct xfrm_userpolicy_id *pi = nlmsg_data(nlh);
struct xfrm_migrate m[XFRM_MAX_DEPTH];
struct xfrm_kmaddress km, *kmp;
u8 type;
... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static int copy_to_user_migrate(const struct xfrm_migrate *m,
struct sk_buff *skb) {
struct xfrm_user_migrate um;
memset(&um, 0, sizeof(um));
um.proto = m->proto;
um.mode = m->mode;
um.reqid = m->reqid;
um.old_family = m->old_family;
memcpy(&um.old_daddr, &m->old_daddr, si... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static int xfrm_send_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
const struct xfrm_migrate *m, int num_migrate,
const struct xfrm_kmaddress *k,
const struct xfrm_encap_tmpl *encap) {
return -ENOPROTOOPT;
}
#endif
#de... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static inline unsigned int xfrm_expire_msgsize(void) {
return NLMSG_ALIGN(sizeof(struct xfrm_user_expire)) +
nla_total_size(sizeof(struct xfrm_mark));
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static int build_expire(struct sk_buff *skb, struct xfrm_state *x,
const struct km_event *c) {
struct xfrm_user_expire *ue;
struct nlmsghdr *nlh;
int err;
nlh = nlmsg_put(skb, c->portid, 0, XFRM_MSG_EXPIRE, sizeof(*ue), 0);
if (nlh == NULL)
return -EMSGSIZE;
ue = nlmsg_data(nlh... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_aevent_state_notify(struct xfrm_state *x,
const struct km_event *c) {
struct net *net = xs_net(x);
struct sk_buff *skb;
int err;
skb = nlmsg_new(xfrm_aevent_msgsize(x), GFP_ATOMIC);
if (skb == NULL)
return -ENOMEM;
err = build_aevent(skb, x, c);
B... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_notify_sa_flush(const struct km_event *c) {
struct net *net = c->net;
struct xfrm_usersa_flush *p;
struct nlmsghdr *nlh;
struct sk_buff *skb;
int len = NLMSG_ALIGN(sizeof(struct xfrm_usersa_flush));
skb = nlmsg_new(len, GFP_ATOMIC);
if (skb == NULL)
return -ENOMEM;
nlh = nlmsg_put... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static inline unsigned int xfrm_sa_len(struct xfrm_state *x) {
unsigned int l = 0;
if (x->aead)
l += nla_total_size(aead_len(x->aead));
if (x->aalg) {
l += nla_total_size(sizeof(struct xfrm_algo) +
(x->aalg->alg_key_len + 7) / 8);
l += nla_total_size(xfrm_alg_auth_len(x->aalg))... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) {
struct net *net = xs_net(x);
struct xfrm_usersa_info *p;
struct xfrm_usersa_id *id;
struct nlmsghdr *nlh;
struct sk_buff *skb;
unsigned int len = xfrm_sa_len(x);
unsigned int headlen;
int err;
headlen = sizeof(*p);
if (c->... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_send_state_notify(struct xfrm_state *x,
const struct km_event *c) {
switch (c->event) {
case XFRM_MSG_EXPIRE:
return xfrm_exp_state_notify(x, c);
case XFRM_MSG_NEWAE:
return xfrm_aevent_state_notify(x, c);
case XFRM_MSG_DELSA:
case XFRM_MSG_UPDSA:
... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c | static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,
u8 *data, int len, int *dir) {
struct net *net = sock_net(sk);
struct xfrm_userpolicy_info *p = (struct xfrm_userpolicy_info *)data;
struct xfrm_user_tmpl *ut = (struct xfrm_user_tmpl *)(p + 1);... | [
1,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_notify_policy_flush(const struct km_event *c) {
struct net *net = c->net;
struct nlmsghdr *nlh;
struct sk_buff *skb;
int err;
skb = nlmsg_new(userpolicy_type_attrsize(), GFP_ATOMIC);
if (skb == NULL)
return -ENOMEM;
nlh = nlmsg_put(skb, c->portid, c->seq, XFRM_MSG_FLUSHPOLICY, 0, 0)... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static int xfrm_send_policy_notify(struct xfrm_policy *xp, int dir,
const struct km_event *c) {
switch (c->event) {
case XFRM_MSG_NEWPOLICY:
case XFRM_MSG_UPDPOLICY:
case XFRM_MSG_DELPOLICY:
return xfrm_notify_policy(xp, dir, c);
case XFRM_MSG_FLUSHPOLICY:
return x... | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static inline unsigned int xfrm_report_msgsize(void) {
return NLMSG_ALIGN(sizeof(struct xfrm_user_report));
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static bool xfrm_is_alive(const struct km_event *c) {
return (bool)xfrm_acquire_is_on(c->net);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static void __net_exit xfrm_user_net_pre_exit(struct net *net) {
RCU_INIT_POINTER(net->xfrm.nlsk, NULL);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static void __net_exit xfrm_user_net_exit(struct list_head *net_exit_list) {
struct net *net;
list_for_each_entry(net, net_exit_list, exit_list)
netlink_kernel_release(net->xfrm.nlsk_stash);
} | [
0,
0
] |
Linux Kernel | net/xfrm/xfrm_user.c |
static void __exit xfrm_user_exit(void) {
xfrm_unregister_km(&netlink_mgr);
unregister_pernet_subsys(&xfrm_user_net_ops);
} | [
0,
0
] |
Linux Kernel | rust/helpers.c |
__noreturn void rust_helper_BUG(void) { BUG(); } | [
0,
0
] |
Linux Kernel | samples/acrn/vm-sample.c |
void vm_exit(int sig) {
sig = sig;
is_running = 0;
ioctl(hsm_fd, ACRN_IOCTL_PAUSE_VM, vmid);
ioctl(hsm_fd, ACRN_IOCTL_DESTROY_IOREQ_CLIENT, 0);
} | [
0,
0
] |
Linux Kernel | samples/auxdisplay/cfag12864b-example.c | static void cfag12864b_not(unsigned char x, unsigned char y) {
if (cfag12864b_isset(x, y))
cfag12864b_unset(x, y);
else
cfag12864b_set(x, y);
} | [
0,
0
] |
Linux Kernel | samples/auxdisplay/cfag12864b-example.c |
static void example(unsigned char n) {
unsigned short i, j;
unsigned char matrix[CFAG12864B_WIDTH * CFAG12864B_HEIGHT];
if (n > EXAMPLES)
return;
printf("Example %i/%i - ", n, EXAMPLES);
switch (n) {
case 1:
printf("Draw points setting bits");
cfag12864b_clear();
for (i = 0; i < CFAG1286... | [
1,
0
] |
Linux Kernel | samples/auxdisplay/cfag12864b-example.c |
int main(int argc, char *argv[]) {
unsigned char n;
if (argc != 2) {
printf("Syntax: %s fbdev\n"
"Usually: /dev/fb0, /dev/fb1...\n",
argv[0]);
return -1;
}
if (cfag12864b_init(argv[1])) {
printf("Can't init %s fbdev\n", argv[1]);
return -2;
}
for (n = 1; n <= EXAMP... | [
0,
0
] |
Linux Kernel | samples/bpf/cookie_uid_helper_example.c |
static void maps_create(void) {
map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(uint32_t),
sizeof(struct stats), 100, NULL);
if (map_fd < 0)
error(1, errno, "map create failed!\n");
} | [
1,
0
] |
Linux Kernel | samples/bpf/cookie_uid_helper_example.c |
static void prog_attach_iptables(char *file) {
int ret;
char rules[256];
if (bpf_obj_pin(prog_fd, file))
error(1, errno, "bpf_obj_pin");
if (strlen(file) > 50) {
printf("file path too long: %s\n", file);
exit(1);
}
ret =
snprintf(rules, sizeof(rules),
"iptables -A OUTPUT -... | [
1,
0
] |
Linux Kernel | samples/bpf/cookie_uid_helper_example.c |
static void print_table(void) {
struct stats curEntry;
uint32_t curN = UINT32_MAX;
uint32_t nextN;
int res;
while (bpf_map_get_next_key(map_fd, &curN, &nextN) > -1) {
curN = nextN;
res = bpf_map_lookup_elem(map_fd, &curN, &curEntry);
if (res < 0) {
error(1, errno, "fail to get entry value ... | [
0,
0
] |
Linux Kernel | samples/bpf/cpustat_user.c | static void cpu_stat_print(void) {
int i, j;
char state_str[sizeof("cstate-9")];
struct cpu_stat_data *data;
printf("\033[2J");
/* Header */
printf("\nCPU states statistics:\n");
printf("%-10s ", "state(ms)");
for (i = 0; i < MAX_CSTATE_ENTRIES; i++) {
sprintf(state_str, "cstate-%d", i);
prin... | [
1,
0
] |
Linux Kernel | samples/bpf/cpustat_user.c |
static void cpu_stat_update(int cstate_fd, int pstate_fd) {
unsigned long key, value;
int c, i;
for (c = 0; c < MAX_CPU; c++) {
for (i = 0; i < MAX_CSTATE_ENTRIES; i++) {
key = c * MAX_CSTATE_ENTRIES + i;
bpf_map_lookup_elem(cstate_fd, &key, &value);
stat_data[c].cstate[i] = value;
}
... | [
0,
0
] |
Linux Kernel | samples/bpf/cpustat_user.c | static int cpu_stat_inject_cpu_idle_event(void) {
int rcpu, i, ret;
cpu_set_t cpumask;
cpu_set_t original_cpumask;
ret = sysconf(_SC_NPROCESSORS_CONF);
if (ret < 0)
return -1;
rcpu = sched_getcpu();
if (rcpu < 0)
return -1;
sched_getaffinity(0, sizeof(original_cpumask), &original_cpumask);
... | [
1,
0
] |
Linux Kernel | samples/bpf/cpustat_user.c |
static void int_exit(int sig) {
cpu_stat_inject_cpu_idle_event();
cpu_stat_inject_cpu_frequency_event();
cpu_stat_update(cstate_map_fd, pstate_map_fd);
cpu_stat_print();
exit(0);
} | [
0,
0
] |
Linux Kernel | samples/bpf/fds_example.c |
static void usage(void) {
printf("Usage: fds_example [...]\n");
printf(" -F <file> File to pin/get object\n");
printf(" -P |- pin object\n");
printf(" -G `- get object\n");
printf(" -m eBPF map mode\n");
printf(" -k <key> |- map key\n");
print... | [
1,
0
] |
Linux Kernel | samples/bpf/fds_example.c |
static int bpf_do_map(const char *file, uint32_t flags, uint32_t key,
uint32_t value) {
int fd, ret;
if (flags & BPF_F_PIN) {
fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(uint32_t),
sizeof(uint32_t), 1024, NULL);
printf("bpf: map fd:%d (%s)\n", fd, str... | [
1,
0
] |
Linux Kernel | samples/bpf/hbm.c |
static void do_error(char *msg, bool errno_flag) {
if (errno_flag)
printf("ERROR: %s, errno: %d\n", msg, errno);
else
printf("ERROR: %s\n", msg);
exit(1);
} | [
0,
0
] |
Linux Kernel | samples/bpf/hbm.c |
static void Usage(void) {
printf("This program loads a cgroup skb BPF program to enforce\n"
"cgroup output (egress) bandwidth limits.\n\n"
"USAGE: hbm [-o] [-d] [-l] [-n <id>] [--no_cn] [-r <rate>]\n"
" [-s] [-t <secs>] [-w] [-h] [prog]\n"
" Where:\n"
" -o ... | [
1,
0
] |
Linux Kernel | samples/bpf/ibumad_user.c |
static void dump_all_counts(void) {
printf("Read 'Class : count'\n");
dump_counts(map_fd[0]);
printf("Write 'Class : count'\n");
dump_counts(map_fd[1]);
} | [
0,
0
] |
Linux Kernel | samples/bpf/ibumad_user.c | static void dump_exit(int sig) {
dump_all_counts();
while (tp_cnt)
bpf_link__destroy(tp_links[--tp_cnt]);
bpf_object__close(obj);
exit(0);
} | [
0,
0
] |
Linux Kernel | samples/bpf/lathist_kern.c |
static unsigned int log2(unsigned int v) {
unsigned int r;
unsigned int shift;
r = (v > 0xFFFF) << 4;
v >>= r;
shift = (v > 0xFF) << 3;
v >>= shift;
r |= shift;
shift = (v > 0xF) << 2;
v >>= shift;
r |= shift;
shift = (v > 0x3) << 1;
v >>= shift;
r |= shift;
r |= (v >> 1);
return r;
} | [
1,
0
] |
Linux Kernel | samples/bpf/lathist_kern.c |
static unsigned int log2l(unsigned long v) {
unsigned int hi = v >> 32;
if (hi)
return log2(hi) + 32;
else
return log2(v);
} | [
1,
0
] |
Linux Kernel | samples/bpf/lathist_user.c |
static void stars(char *str, long val, long max, int width) {
int i;
for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++)
str[i] = '*';
if (val > max)
str[i - 1] = '+';
str[i] = '\0';
} | [
1,
0
] |
Linux Kernel | samples/bpf/lathist_user.c | int main(int argc, char **argv) {
struct bpf_link *links[2];
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
int map_fd, i = 0;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
fprintf(stderr,... | [
1,
0
] |
Linux Kernel | samples/bpf/lwt_len_hist_kern.c | int do_len_hist(struct __sk_buff *skb) {
__u64 *value, key, init_val = 1;
key = log2l(skb->len);
value = bpf_map_lookup_elem(&lwt_len_hist_map, &key);
if (value)
__sync_fetch_and_add(value, 1);
else
bpf_map_update_elem(&lwt_len_hist_map, &key, &init_val, BPF_ANY);
return BPF_OK;
} | [
0,
0
] |
Linux Kernel | samples/bpf/lwt_len_hist_user.c |
int main(int argc, char **argv) {
unsigned int nr_cpus = bpf_num_possible_cpus();
const char *map_filename = "/sys/fs/bpf/tc/globals/lwt_len_hist_map";
uint64_t values[nr_cpus], sum, max_value = 0, data[MAX_INDEX] = {};
uint64_t key = 0, next_key, max_key = 0;
char starstr[MAX_STARS];
int i, map_fd;
map... | [
1,
0
] |
Linux Kernel | samples/bpf/map_perf_test_kern.c | int stress_percpu_hmap_alloc(struct pt_regs *ctx) {
u32 key = bpf_get_current_pid_tgid();
long init_val = 1;
long *value;
int i;
for (i = 0; i < 10; i++) {
bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY);
value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key);
if (value)
... | [
0,
0
] |
Linux Kernel | samples/bpf/map_perf_test_kern.c | int stress_lpm_trie_map_alloc(struct pt_regs *ctx) {
union {
u32 b32[2];
u8 b8[8];
} key;
unsigned int i;
key.b32[0] = 32;
key.b8[4] = 192;
key.b8[5] = 168;
key.b8[6] = 0;
key.b8[7] = 1;
#pragma clang loop unroll(full)
for (i = 0; i < 32; ++i)
bpf_map_lookup_elem(&lpm_trie_map_alloc, &ke... | [
0,
0
] |
Linux Kernel | samples/bpf/map_perf_test_kern.c | int stress_array_map_lookup(struct pt_regs *ctx) {
u32 key = 1, i;
long *value;
#pragma clang loop unroll(full)
for (i = 0; i < 64; ++i)
value = bpf_map_lookup_elem(&array_map, &key);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/map_perf_test_user.c |
static void test_lpm_kmalloc(int cpu) {
__u64 start_time;
int i;
start_time = time_get_ns();
for (i = 0; i < max_cnt; i++)
syscall(__NR_gettid);
printf("%d:lpm_perf kmalloc %lld events per sec\n", cpu,
max_cnt * 1000000000ll / (time_get_ns() - start_time));
} | [
0,
0
] |
Linux Kernel | samples/bpf/map_perf_test_user.c |
static void test_hash_lookup(int cpu) {
__u64 start_time;
int i;
start_time = time_get_ns();
for (i = 0; i < max_cnt; i++)
syscall(__NR_getpgid, 0);
printf("%d:hash_lookup %lld lookups per sec\n", cpu,
max_cnt * 1000000000ll * 64 / (time_get_ns() - start_time));
} | [
0,
0
] |
Linux Kernel | samples/bpf/map_perf_test_user.c | static void fixup_map(struct bpf_object *obj) {
struct bpf_map *map;
int i;
bpf_object__for_each_map(map, obj) {
const char *name = bpf_map__name(map);
for (i = 0; i < NR_TESTS; i++) {
if (!strcmp(test_map_names[i], name) && (check_test_flags(i))) {
bpf_map__set_max_entries(map, num_map_en... | [
0,
0
] |
Linux Kernel | samples/bpf/offwaketime_kern.c | int waker(struct pt_regs *ctx) {
struct task_struct *p = (void *)PT_REGS_PARM1(ctx);
struct wokeby_t woke;
u32 pid;
pid = _(p->pid);
bpf_get_current_comm(&woke.name, sizeof(woke.name));
woke.ret = bpf_get_stackid(ctx, &stackmap, STACKID_FLAGS);
bpf_map_update_elem(&wokeby, &pid, &woke, BPF_ANY);
retu... | [
1,
0
] |
Linux Kernel | samples/bpf/offwaketime_user.c | int main(int argc, char **argv) {
struct bpf_object *obj = NULL;
struct bpf_link *links[2];
struct bpf_program *prog;
int delay = 1, i = 0;
char filename[256];
if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
return 2;
}
snprintf(filename, sizeof(filename), "%s_kern.o", arg... | [
1,
0
] |
Linux Kernel | samples/bpf/parse_ldabs.c | int handle_ingress(struct __sk_buff *skb) {
__u64 troff = ETH_HLEN + sizeof(struct iphdr);
if (load_half(skb, offsetof(struct ethhdr, h_proto)) != ETH_P_IP)
return 0;
if (load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol)) !=
IPPROTO_UDP ||
load_byte(skb, ETH_HLEN) != 0x45)
return... | [
1,
0
] |
Linux Kernel | samples/bpf/parse_varlen.c | int handle_ingress(struct __sk_buff *skb) {
void *data = (void *)(long)skb->data;
struct ethhdr *eth = data;
void *data_end = (void *)(long)skb->data_end;
uint64_t h_proto, nh_off;
nh_off = sizeof(*eth);
if (data + nh_off > data_end)
return 0;
h_proto = eth->h_proto;
if (h_proto == ETH_P_8021Q ||... | [
1,
0
] |
Linux Kernel | samples/bpf/sampleip_kern.c | int do_sample(struct bpf_perf_event_data *ctx) {
u64 ip;
u32 *value, init_val = 1;
ip = PT_REGS_IP(&ctx->regs);
value = bpf_map_lookup_elem(&ip_map, &ip);
if (value)
*value += 1;
else
bpf_map_update_elem(&ip_map, &ip, &init_val, BPF_NOEXIST);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/sampleip_user.c | static void print_ip_map(int fd) {
struct ksym *sym;
__u64 key, next_key;
__u32 value;
int i, max;
printf("%-19s %-32s %s\n", "ADDR", "KSYM", "COUNT");
key = 0, i = 0;
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &value);
counts[i].ip = next_key;
... | [
1,
0
] |
Linux Kernel | samples/bpf/sockex1_kern.c | int bpf_prog1(struct __sk_buff *skb) {
int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
long *value;
if (skb->pkt_type != PACKET_OUTGOING)
return 0;
value = bpf_map_lookup_elem(&my_map, &index);
if (value)
__sync_fetch_and_add(value, skb->len);
return 0;
} | [
0,
0
] |
Linux Kernel | samples/bpf/sockex1_user.c |
int main(int ac, char **argv) {
struct bpf_object *obj;
struct bpf_program *prog;
int map_fd, prog_fd;
char filename[256];
int i, sock, err;
FILE *f;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1;
... | [
1,
0
] |
Linux Kernel | samples/bpf/sockex2_kern.c |
static inline __u64 parse_ipv6(struct __sk_buff *skb, __u64 nhoff,
__u64 *ip_proto, struct flow_key_record *flow) {
*ip_proto = load_byte(skb, nhoff + offsetof(struct ipv6hdr, nexthdr));
flow->src = ipv6_addr_hash(skb, nhoff + offsetof(struct ipv6hdr, saddr));
flow->dst = ipv6_addr... | [
1,
0
] |
Linux Kernel | samples/bpf/sockex3_kern.c |
static inline int ip_is_fragment(struct __sk_buff *ctx, __u64 nhoff) {
return load_half(ctx, nhoff + offsetof(struct iphdr, frag_off)) &
(IP_MF | IP_OFFSET);
} | [
0,
0
] |
Linux Kernel | samples/bpf/sockex3_kern.c | static struct globals *this_cpu_globals(void) {
u32 key = bpf_get_smp_processor_id();
return bpf_map_lookup_elem(&percpu_map, &key);
} | [
0,
0
] |
Linux Kernel | samples/bpf/sockex3_kern.c |
static void update_stats(struct __sk_buff *skb, struct globals *g) {
struct flow_key_record key = g->flow;
struct pair *value;
value = bpf_map_lookup_elem(&hash_map, &key);
if (value) {
__sync_fetch_and_add(&value->packets, 1);
__sync_fetch_and_add(&value->bytes, skb->len);
} else {
struct pair ... | [
0,
0
] |
Linux Kernel | samples/bpf/sockex3_kern.c | static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto) {
switch (proto) {
case ETH_P_8021Q:
case ETH_P_8021AD:
bpf_tail_call(skb, &prog_array_init, PARSE_VLAN);
break;
case ETH_P_MPLS_UC:
case ETH_P_MPLS_MC:
bpf_tail_call(skb, &prog_array_init, PARSE_MPLS);
break;
case ETH_P_IP... | [
1,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.