middlebox/ebpf/helpers/xdp_loader.c
/* Pinning maps under /sys/fs/bpf in subdir */
Pinning maps under /sys/fs/bpf in subdir
Pinning maps under / sys / fs / bpf in subdir
int pin_maps_in_bpf_object(struct bpf_object *bpf_obj, struct config *cfg)
{
	char map_filename[PATH_MAX];
	int err, len, i;
	for (i=0;i<MAP_COUNT;i++) {
		len = snprintf(map_filename, PATH_MAX, "%s/%s/%s",
				pin_basedir, cfg->ifname, map_names[i]);
		if (len < 0) {
			fprintf(stderr, "ERR: creating map_name\n");
			return EXIT_FAIL_OPTION;
		}
		if (access(map_filename, F_OK ) != -1 ) {
			if (verbose)
				printf(" - Unpinning (remove) prev maps in %s/\n",
						cfg->pin_dir);
			err = bpf_object__unpin_maps(bpf_obj, cfg->pin_dir);
			if (err) {
				fprintf(stderr, "ERR: UNpinning maps in %s\n", cfg->pin_dir);
				return EXIT_FAIL_BPF;
			}
		}
	}
	if (verbose)
		printf(" - Pinning maps in %s/\n", cfg->pin_dir);
	err = bpf_object__pin_maps(bpf_obj, cfg->pin_dir);
	if (err)
		return EXIT_FAIL_BPF;
	return 0;
}
int pin_maps_in_bpf_object ( struct bpf_object * bpf_obj , struct config * cfg ) { char map_filename [ PATH_MAX ] ; int err , len , i ; for ( i = 0 ; i < MAP_COUNT ; i ++ ) { len = snprintf ( map_filename , PATH_MAX , " " , pin_basedir , cfg -> ifname , map_names [ i ] ) ; if ( len < 0 ) { fprintf ( stderr , " \n " ) ; return EXIT_FAIL_OPTION ; } if ( access ( map_filename , F_OK ) != -1 ) { if ( verbose ) printf ( " \n " , cfg -> pin_dir ) ; err = bpf_object__unpin_maps ( bpf_obj , cfg -> pin_dir ) ; if ( err ) { fprintf ( stderr , " \n " , cfg -> pin_dir ) ; return EXIT_FAIL_BPF ; } } } if ( verbose ) printf ( " \n " , cfg -> pin_dir ) ; err = bpf_object__pin_maps ( bpf_obj , cfg -> pin_dir ) ; if ( err ) return EXIT_FAIL_BPF ; return 0 ; }
Pinning maps under /sys/fs/bpf in subdir
Pinning maps under / sys / fs / bpf in subdir
/* Existing/previous XDP prog might not have cleaned up */ /* Basically calls unlink(3) on map_filename */ /* This will pin all maps in our bpf_object */