Media playback is unsupported on your device Media caption President Obama told the BBC he would deliver a blunt message on gay rights when he travelled to Africa

US President Barack Obama has told the BBC he will continue to deliver his "blunt message" to African leaders about gay rights and discrimination.

"I am not a fan of discrimination and bullying of anybody on the basis of race... religion... sexual orientation or gender," he said.

Mr Obama is on his way to visit his ancestral home of Kenya and he will also go to Ethiopia.

He said the trip showed US commitment to fighting terror in East Africa.

In the wide-ranging interview with the BBC's North America editor Jon Sopel before he left Washington, President Obama also said:

His failure to pass "common sense gun safety laws" in the US was the greatest frustration of his presidency

The UK must stay in the EU to have influence on the world stage

He is confident the Iran nuclear deal will be passed by Congress

Syria needs a political solution in order to defeat the Islamic State group

Despite racial tensions, the US is becoming more diverse and more tolerant.

Read the full transcript of his interview

It will be Mr Obama's first visit to Kenya since becoming president.

He will also become the first US leader to address the African Union when he travels on to Ethiopia on Sunday.

With hours to go till Mr Obama lands in the Kenyan capital, Nairobi is in lockdown with many streets closed and people opting to stay at home.

At the scene - Milton Nkosi, BBC News, Nairobi

Image copyright Reuters

Nairobi's streets - notorious for their long traffic jams - are empty. This is because of one of the largest security clampdowns the Kenyan capital has ever seen.

There is visible policing almost everywhere and security convoy sirens have been booming across the city all day.

President Obama is seen as Kenya's son - and this is a homecoming. But while Kenyans are happy and excited about his first visit as US president, they are paying the price of having their movements restricted.

Mosques have had to open and close early to avoid many road closures. Some businesses have had to shut early to avoid being trapped.

But it is a price they are happy to pay to host the most powerful man in the world.

This is Mr Obama's fifth trip to Africa as president, but despite his close family links to Kenya, he has faced criticism in some African countries over the legalisation of gay marriage in the US.

However, the president told the BBC he would not fall silent on the issue.

Media playback is unsupported on your device Media caption Kenyans tell the BBC their feelings on President Obama's comments about gay rights

The US leader also agreed that some African governments, including Kenya's, needed to improve their records on human rights and democracy.

However, he defended his decision to engage with and visit those governments.

"Well, they're not ideal institutions. But what we found is, that when we combined blunt talk with engagement, that gives us the best opportunity to influence and open up space for civil society."

Obama on Africa:

Image copyright Amanda Lucidon

US-Africa ties

"I'll be the first US president to not only visit Kenya and Ethiopia, but also to address the continent as a whole, building off the African summit that we did here which was historic and has, I think, deepened the kinds of already strong relationships that we have across the continent."

Giving the young opportunities

"A while back, when we started looking at strategies to reach out to the Muslim world, to reach out to developed countries, a common theme emerged, which was people are not interested in just being... patronised. And being given aid. They're interested in building capacity."

On China

"We welcome Chinese aid into Africa. I think we think that's a good thing. We don't want to discourage it. As I've said before, what I also want to make sure though is that trade is benefiting the ordinary Kenyan and the ordinary Ethiopian and the ordinary Guinean and not just a few elites."

On discrimination

"As somebody who has family in Kenya and knows the history of how the country so often is held back because women and girls are not treated fairly, I think those same values apply when it comes to different sexual orientations."

The presidential body swerve

Five things we learned from Obama interview

President Obama said the US would continue to co-operate with Kenya and other East African nations to counter the threats from Islamist extremists groups.

He is due to address a global entrepreneurship summit in the capital, Nairobi this weekend, which the US state department said could provide "a target for terrorists".

But Mr Obama told the BBC that there is a link between security and entrepreneurship.

"When [people] have a sense of control of their own destiny, then they're less vulnerable to the propaganda and twisted ideologies that have been attracting young people - particularly now being turbocharged through social media."

Image copyright Reuters Image caption Kenya is getting ready to welcome the US president

Kenya is one of the top recipients of US military aid and in recent years has suffered attacks from Somalia's Islamist al-Shabab militants.

Away from human rights and security, there is also the issue of trade. In 2014, trade between the two countries reached $2.2bn (£1.4bn).